Search code examples
ioscloudkit

Does CKRecordZoneID need to be unique per user?


Is a CloudKit record zone created per user basis, or does it apply to everyone?

A CKRecordZoneID object uniquely identifies a record zone in a database.

This seems to imply that it's affecting for everyone.

A record zone ID distinguishes one zone from another by a name string and the ID of the user that created the zone.

However, the fact that the ID appends the owner name, made it sound like it's per user basis?

The reason why I'm asking is I'd like to know if I can create a single RecordZoneID for the app or does it need to be stored per user (in NSUserDefaults)


Solution

  • The short answer is that zone names only need to be unique among the other zones in a user's private database.

    There's a subtle but important difference between a CKRecordZoneID and a zone name.

    A CKRecordZoneID must be unique across your entire container, but a CKRecordZoneID is more than just the zone name.

    If you look at CKRecordZoneID you'll see that it has both a zoneName property and an ownerName property. The ownerName is the record ID of the current user (or CKOwnerDefaultName, which gets replaced by the real user ID before the value is sent to the server).

    The combination of zoneName and ownerName must be unique across the container, but since every user has their own unique user ID (which is used for ownerName) you can create a zone with the same zoneName for every user and not have any conflicts.