Learn Courses My Dashboard

Firebase > CloudKit?


I’m going through the courses here ad noticed there are no CloudKit modules. I’m having a hunt around the net, but was wondering if anyone here could weigh in as to why Firebase dominates the database section of the courses, and there’s no mention of CloudKit.

Thanks & regards

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:

  1. Storing Data as Files – are you building a DropBox/Google Drive kind of app?
  2. Storing Unstructured Data – do you want to build an app that syncs app settings like a game?
  3. 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:

  1. 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.
  2. 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.

  1. When you put this app into production, would you want this available on the web and other mobile platforms such as Android?

Using CloudKit, you can share your data across devices and you can also provide access to web users using the javascript support, but it’ll be difficult to share this data to Android should you choose to support it later on. One way to do it would be to create a middle API that’ll serve the data from CloudKit to your Android app but it’s up to you to implement a security of your own.

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.

1 Like

inaki that’s great info, thanks for the incredibly well thought out and comprehensive response.

I’ll have a solid read through it.

Much appreciated