Frederic Adda
Frederic Adda

Reputation: 6092

CloudKit CKRecordZone

I have been fiddling with CloudKit for some time now, but I can't find a real-life example for how to use CKRecordZone. I understand their capabilities (namely, grouping records, especially for subscriptions), but does someone have a real experience of having used them, and to map which concept ?

Thanks

Upvotes: 8

Views: 1213

Answers (3)

malhal
malhal

Reputation: 30561

The Apple News app uses two zones in the private database for the user's information: ReadingList and ReadingHistory. ReadingList stores news article IDs that have been bookmarked; ReadingHistory stores news article IDs that have been read. By separating the article IDs into two different zones it allows them to be efficiently synced. For example, if an article is only read on a device (and not bookmarked), then the other device receives a notification that the ReadingHistory zone has changed, then it only has to sync that zone rather than both. For more info, you can read my full write up on the News app's syncing behavior here.

Upvotes: 7

karbonator
karbonator

Reputation: 181

CloudKit record zones give you three main benefits:

  1. It allows you to do atomic operations (either all or none of the changes will get applied)
  2. It gives you sync capabilities, so you can fetch record changes from a previous point in time (with a change token) as opposed to having to download the full list of records every time you talk with the server.
  3. It's useful for logically grouping records that belong together.

Upvotes: 6

Frederic Adda
Frederic Adda

Reputation: 6092

Also, it may be useful when you want to create a CKSubscription that monitors all records in a specified record zone (zone-based, instead of query-based).

Upvotes: 5

Related Questions