CloudKit 101

CloudKit 101

Note: this article is a revision of the article I wrote back in 2017. If you’d like to listen to an informal conversation about CloudKit, check out iPhreaks episode #226.

Apple introduced CloudKit in 2014. Since then, it has received many improvements, like the ability to use it outside Apple's platforms and to use it on apps distributed outside the App Store on the Mac.

[…]

Unfortunately, whenever talking about Apple and the cloud, the question “is this safe to use in production?” arrises. It's true that Apple has had issues before when it comes to cloud services, but the good news is this doesn't apply to CloudKit.

You don't have to take my word for it. Do you use Apple Notes? Photos? iCloud Drive? Activity sharing on Apple Watch? These are all powered by CloudKit and they've been working just fine for me.

[…]

That said, it can still be beneficial to know the ins and outs of CloudKit if you wish to implement your own sync solution or use it for other purposes. If that’s the case, read on.

Even if you're convinced CloudKit is good and works well, it doesn't mean it's the best solution for your particular problem, since there are some applications where CloudKit is the best solution and some where it's not.

[…]

Example: a note taking app where the user can create and read notes on any device associated with their iCloud account.

Alternatives: Realm Mobile Platform, Firebase, iCloud KVS, iCloud Documents, custom web app.

[…]

The public database on CloudKit is a good place to store remote app configuration in general. In my app ChibiStudio, I use it to configure feature switches so that features can be rolled out or rolled back after a build has been released for customers.

[…]

You can use CloudKit just to get the user's unique identifier and use it as an authentication method for your service. These days you can also use Sign in with Apple, but that’s a little bit more involved and less transparent to the user than simply getting access to their anonymous user identifier.

You can use CloudKit to send notifications, eliminating the need to use a 3rd party service or custom web server.

[…]

If your app works primarily with documents, CloudKit is probably not the best tool for the job. In this case you'd be better off using Google Drive, DropBox, iCloud Drive or other similar services. You can store large files in CloudKit, but it might not be the best solution if you have a document-based app.

Examples: text editors like Pages, image editors like Pixelmator and Sketch.

To store simple user preferences or very small amounts of data, use iCloud KVS (NSUbiquitousKeyValueStore).

[…]

CloudKit is a first-party technology which comes pre-installed on all devices, doesn't require a separate authentication besides the user's iCloud account, has powerful features (like you'll see in the rest of this article) and has a great chance of continuing to exist and be supported for the foreseeable future. These are the main reasons why I think CloudKit is a better option than most 3rd party services.

[…]

Simply put: you're not going to be paying for CloudKit. Period.

What Apple has done is they have created a system which prevents abuse. Therefore, if you do a "regular" use of the service, it'll always be free.

[…]

But wait, there's more! The private database counts against your user's iCloud quota, so if you're only using the private database in your app, you'll never even start to consume your app's quota.

[…]