Local Cache of CloudKit Records

Viewed 1675

There's a chapter called Maintaining Local Cache of CloudKit Records in CloudKit documentation on Apple's web site. However, everywhere online people say it's close to impossible to store offline data with CloudKit. I'm relatively new iOS developer. Did anybody tried implementing offline data storage (on device) as per Apple's docs?

1 Answers

If you want true, offline-first data for your app, then yes, you need to add a database of some kind.

Every time you update a record, save it to your database and push the updated record to CloudKit. You can also subscribe to CloudKit changes and update your local database as record changes come in.

Core Data and SQLite are common options. I happen to use the Realm database, which I consider to be a bit simpler to use than Core Data or SQLite. I set it up so that my app's UI only interacts with the offline data in the database (so that it's always available). CloudKit and my Realm database work together to keep the data up-to-date, but my UI never tries to rely on the presence of transitory CloudKit records.

I hope that helps.

Related