Good question. As you know, YapDatabase is capable of working with any CloudKit database. Which includes both the public & private database (or both simultaneously). But it’s important to understand what YapDatabase does for you, and what it does not do for you.
If we distill any sync framework down to its bare essentials we get:
1. system for detecting changes to sync'd objects, and extracting something that needs to get pushed to the cloud
2. persistently storing the change-set(s) that need to get pushed to the cloud
3. system for handling merges and conflicts
4. sync service specific code for uploading & downloading changes
YapDatabaseCloudKit handles # 1, 2 & 3. But you are responsible for #4. And there’s a good reason for this, which I’ll get to momentarily. But first let’s look at the CloudKitTodo sample project.
#1, 2 & 3 are handled primarily within [DatabaseManager setupCloudKitExtension]
#4 is handled by the CloudKitManager class.
You’ll notice the CloudKitManager class performs 3 tasks every time it starts:
- Create CKRecordZone (if needed)
- Create CKSubscription for recordZone (if needed)
- Fetches changes (for the recordZone in the privateDatabase)
This code is a good blueprint to start with. But you’ll need to tweak it to fit your needs.
In particular, this code only supports a single recordZone. If you wish to support another zone (i.e. backgroundZone in publicDatabase), then you’ll need to expand upon this class. The good news is that the code sample is a great starting point.
So why doesn’t YapDatabaseCloudKit do everything for you ?
Apple’s CloudKit system is capable of storing hundreds of thousands of gigabytes of data. It’s not feasible to blindly download all this data, especially on a mobile device. This is app specific logic that needs to be handled by the app developer. For example:
Say you’re making a public “meet-up” app, where user’s can announce meet-up events. Each event has a time & location. And there might be hundreds of thousands of events every single day. But for a specific user of the app, you only want to download events for a certain location (near the user), and a certain time period (today).
You’ll notice that the logic for doing this is very different from the logic of downloading every single ToDo item in a user’s private database. However, I felt that the todo app represented the most common scenario (syncing all items from a user’s private database). And that’s why I used it as the sample application.
Let me know if you have other questions.