I am making an app (in Swift) which needs to run in offline and online mode. When its in offline mode, data will be stored locally on CoreData. Once it detects network (online) it should sync with server and update the backend database. How should one go about it. Are there libraries or pods?
I have seen this post but nothing is actionable. It is too high level and I am not sure where to start. I have seen this link from Ray Wenderlich but don't know how to translate to Swift.
Any tutorial links will also be helpful
Add new BOOL
attribute
to your CoreData Entity
and name it as synched
. This will basically store the synched status for each object.
Now you will have to check for internet connectivity. Refer to this link
Whenever you have internet connectivity, just fetch the objects from CoreData
using the following NSPredicate
in your fetch request:
let isSynchedPredicate = NSPredicate(format: "synched = %@", false)
Now you can just use your webservice to sync and update all the fetched objects to server. On successfull upload, DONOT forget to change the synched
property to true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With