swiftcore-dataicloudcloudkitensembles

Store CoreData in iCloud


I am currently creating a macOs application that stores customer data in a CoreData database.

Now I want that data to be stored in the iCloud. The idea is that every user has its own data in his iCloud. If he uses more than one Mac/iOS device he can access his data.

So I don't a centralized data storage for all customers but a data store for each customer separately.

I have read through some topics regarding CloudKit but was confused about it in general:

Can someone give me his experience in this?

Thank you


Solution

  • CloudKit is quite extensive. It provides three types of database:

    1. Public, which can be shared by everyone.
    2. Private, which is specific to one iCloud account.
    3. Shared, which is someone's private database, but which you have been given access to.

    This gives you plenty of options, and the case you are asking about, where data is shared between the devices of a single iCloud user, fits nicely into the private database. In other words, CloudKit would work very well for you.

    As others have already stated, CloudKit provides you the online storage you need to move data between devices, but it doesn't provide a complete mechanism for that. That is where frameworks like Ensembles come in; they are built on top of CloudKit and other services to handle all the bookkeeping involved in keeping two devices separated in time and space in sync. (Disclaimer: I am the developer of the Ensembles framework.)

    You don't have to use a framework like Ensembles; you can just communicate with CloudKit directly, but you should not underestimate how much time and skill it would take to develop a fully syncing app with Core Data. Depending on your dataset, there can be a lot of gotchas. Ensembles and similar frameworks do a lot for you:

    In short, you can do it yourself, but I wouldn't recommend it. If you want Core Data sync, I recommend Ensembles, or to look at other libraries like Seam (I have not used this, but it seems popular).

    If you are not married to Core Data, you could look at options like Realm and Firebase, which effectively handle the sync problem and the client API in one hit.