Hacker, Concerned Citizen and Avid Reader. Interested in politics, economy and history. Founder & CEO of Melluli Technologies. Bengaluru, India

Image

End of the road for iCloud CoreData Storage & Sync?

Background

Core Data is a convenient way to store persistent relational data in iOS apps. It is built on top of sqlite and is a easy framework with plenty of documentation. However a common need in apps is to sync app data between different installations on multiple iOS devices that a user commonly owns, like on an iPhone and iPad, and the same app is installed on both the devices. Apple realised this some time back and allowed syncing of app coredata logs via something called UbiquityStoreManager between devices which use the same iCloud account. This is not a very straight forward solution and there is every chance of data conflicts if same data is modified on two different devices and a sync is triggered. Core Data framework provides for handling this via NSNotifications like NSPersistentStoreDidImportUbiquitousContentChangesNotification, etc.

Data In iCloud Today

While I’m not going into details of how iCloud Coredata sync works, the fact is, it always caused issues and the objective was never satisfactorily achieved. Meanwhile Apple moved on to much more ambitious iCloud data framework called Cloud Kit. In fact there are three ways to store data on iCloud now -

  • Key-Value storage
  • iCloud Documents
  • Cloud Kit

Apparently iCloud Coredata sync was originally built using (2) above i.e. iCloud Documents. And then Apple became not very keen on maintaining this implementation. It has since -

  • Deprecated NSPersistentStoreUbiquitousContentNameKey in iOS 10
  • Nothing in docs2 contain anything useful to help in new implementations of iCloud Coredata sync
  • iCloud Programming Guide for Core Data - Apparently this link is unlinked in all documentation and specifically can be see in above mentioned doc.

What Next?

Apple probably is asking us to use CloudKit to manage a cloud database and manually handle the sync between local and cloud databases. Pity for those who have gone through the older route. Nevertheless a better step forward, albeit without any clarity, for at-least we know now that the older mechanism expectations were neither met earlier and will not be met in future. Apple has charted a new path for us to take in this case using Cloud Kit.

Hope this helps anyone trying to develop a coredata based app and want to sync that data between devices, to consider the costs of implementing CloudKit separately.

Adios!

Footnotes -