2

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:

  • CloudKit provides a data storage for global data (e.g. I want to store data of customer)
  • Is there a possibility to story CoreData to an iCloud account of every customer?
  • If so is this possible by CloudKit or do I have to use a third party lib like Ensembles? (That mentioned there was a thread of 2016 saying that Apple dismissed the possiblity to use CoreData via iCloud but only 3rd party libs like Ensemble would work now)

Can someone give me his experience in this?

Thank you

Oliver Koehler
  • 711
  • 2
  • 8
  • 24
  • the database will be isolated in iCloud by users' iTunes Accounts therefore it is ideal to store user-related data only, there will be no direct gateway to share data between different iCloud users; if that fits your concept then the only thing you actually __must__ worry about is how you'd intent to resolve conflicts in CoreData; the rest is storm in a teacup. – holex Nov 23 '17 at 14:36
  • @holex that is exactly what I want. Users of a specific iTunes/iCloud account should only see their data. So this could be achieved by using CloudKit? Or do you suggest a solution based on something like Ensembles? – Oliver Koehler Nov 23 '17 at 14:57
  • in that case your biggest challenge is only establishing a policy for resolving _conflicts_ in CoreData only, because after that you just need to save the database into the app's iCloud container and everything else will be managed by iOS in background. I don't recommend to use any 3rd party stuff for that – simply because you just won't need it and it would increase the complexity (imho). – holex Nov 23 '17 at 15:01

1 Answers1

3

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:

  • Ensuring changes are played back in the same order on every device
  • Handling concurrent changes on two different devices
  • Removing old and redundant data
  • Keeping memory usage low by providing batching, which is very important on iOS

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.

Drew McCormack
  • 3,490
  • 1
  • 19
  • 23