Breaking News
Use
Structure:-
I used the MVVM structure with use cases to cleanly achieve separation of concern for the user interface from the application logic. By using this architecture it helped in
- Independent of UI: The UI can change easily, without changing the rest of the system as we can substitute the table view with a collection view and we will not have to touch our logic
- Independent of the database and network: I can easily change them without breaking business rules.
- Testable: The business rules can be tested without the UI, database, web server, or any other external element.
Data Flow
- View(UI) calls a method from ViewModel.
- ViewModel executes Use Case.
- Use Case call network API and return the articles to viewModel.
- Information flows back to the View(UI) where we display the list of items.
Caching:-
- I used UserDefauls to cache simple configuration(user favorites and date of last caching)
- I used documents directory to cache articles and refresh it every 15 minutes:
When thinking about persistence in iOS apps:
The first choice might be Core Data but Core Data is best used when we have a lot of relationships between our objects as it is primarily an object graph manager that happens to have a persistence layer, our second choice might be realm but in our case, the overhead work is not worth it so saving a .plist file to disk allows us to easily add, remove our model objects without much code and the code is more swift friendly and it’s easy to understand
Enums:-
Using enum is very pretty as I can set the cases and extend these cases with variables, I used them in
- Managing view states
- Listing differrent categories and countries
- Build Alamofire network request
Pods
- Alamofire: HTTP networking library to simplify common REST services.
- SDWebImage: Async image downloader with cache support.
- DropDown: Design drop down.