It’s great to know that you’re eager to learn CloudKit, the API is great with storage and syncing. I’ve seen a demo app in r/swift subreddit that does the syncing and it looks great!
CWC doesn’t yet have a course for CloudKit, but if you’re interested the first thing we need to do is to determine whether CloudKit is right for your app.
There are three use cases Apple mentioned in that article:
Storing Data as Files – are you building a DropBox/Google Drive kind of app?
Storing Unstructured Data – do you want to build an app that syncs app settings like a game?
Storing Objects – or do you want to store complex objects and relationships, like the majority of the apps with online features?
If your app falls under use case #1, you can use iCloud document storage using FileManager’s url(forUbiquityContainerIdentifier:) function.
If your app falls under use case #2, you can use iCloud key-value storage using NSUbiquitousKeyValueStore.
If your app falls under use case #3, you have two options using CloudKit:
Using CoreData with CloudKit – basically syncs locally stored data to iCloud. You use CoreData to manage your app schema and store local data, then CloudKit replicates this data to iCloud and takes care of the sync. When you want to use a single container for your app, and your object schema is relational, this is definitely the way to go. If you’re interested to learn more about CoreData, we have a course for that: Core Data Tutorials. You can follow through the tutorial even you choose to enable the use of CloudKit on the project creation prompt. It’s important to know that using CoreData with iCloud only syncs private data, and does not support CloudKit features such as live queries to public data and shared private data. To learn more about the differences between public data, private data, and shared data, you may read: Designing with CloudKit - iCloud - Apple Developer.
- Using CloudKit directly – it’s more complex but gives you full control over your data. This means you can make full use of CloudKit’s features, and you can design your app to not limit its schema to a single container. To get started with CloudKit, you can read Enabling CloudKit in Your App | Apple Developer Documentation.
Falling back to your title about weighing in CloudKit and Firebase, we can add a fourth criteria that’s not mentioned on the previous article to determine if CloudKit is right for your app.
- When you put this app into production, would you want this available on the web and other mobile platforms such as Android?
Firebase, on the other hand, has native SDKs that can be integrated into all three platforms. It offers similar functionalities as CloudKit but operates differently under the hood.
You can never go wrong when you choose either of the two, it all boils down to what your app’s needs are, what platforms you wanted your app to scale into, and how you design your schema.