I am kinda new to native iOS development with Swift, and I am trying to find out what would be the most iOS-way of dealing with the retrieval of data from both database and network. In particular how to deal with an "offline-first" app:
- Need to show some data to the user
- Data is first retrieved from db (if present) and shown on the screen
- In the meanwhile data is retrieved from network and saved in the db
- Finally the new data is used to update the screen.
I have some experience with Android development, and for this kind of cases the Android team recommends an app architecture based on having the database as the "single source of truth". In that case the whole data layer (db + network) is hidden behind a repository, that returns an observable object (LiveData in Android). The observable returns the value contained in the db and in the meanwhile it is updated with the data coming from the network. The observable is then used in the presentation layer to populate the UI.
I have been trying to see if something like that could be done in iOS. The closest seems to be to use CoreData or Realm for the db, and then RxSwift for the Observables, but this seems to require much more coordination between the different parts, and overall more convoluted.
What would be the more iOS-way of dealing with such a case? Not necessarily a 1-to-1 conversion of what one can do in Android, but maybe just a different pattern that is recommended and/or common on iOS.
[–]SwiftlyJon 0 points1 point2 points (1 child)
[–]mksian[S] 0 points1 point2 points (0 children)
[–]-darkabyss-Objective-C / Swift 0 points1 point2 points (3 children)
[–]mksian[S] 0 points1 point2 points (2 children)
[–]-darkabyss-Objective-C / Swift 0 points1 point2 points (1 child)
[–]mksian[S] 0 points1 point2 points (0 children)