An object that uniquely identifies a record in a database.
- iOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+Beta
- tvOS 9.0+
- watchOS 3.0+
A record ID object consists of a name string and a zone ID. The name string is an ASCII string not exceeding 255 characters in length. For automatically created records, the ID name string is based on a UUID and is therefore guaranteed to be unique. When creating your own record ID objects, you are free to use names that have more meaning to your app or to the user, as long as each name is unique within the specified zone. For example, you might use a document name for the name string.
Record IDs must be unique within a given database, but you can reuse record IDs in different databases. Each container has a public and private database, and the private database is different for each unique user. This configuration lets you reuse record IDs for each user's private data, but in the public database only one record may use a specific record ID.
Record ID objects are normally created automatically when you create a new record, but you might also create IDs in several specific situations. For example, you must create record ID objects when you want to save a record in a zone other than the default zone. You can also create record ID objects when you want to retrieve records whose IDs you know from a database.
This class is not intended to be subclassed.
Interacting with Record IDs
After you create a
CKRecord object, interactions with that object typically involve creating a new record or retrieving an existing record from a database.
You might also use record IDs when you cannot use a
CKReference object to refer to a record. References are only valid within a single zone of a database. To refer to objects outside of the current zone or database, save the strings in the record’s
CKRecord objects. When you want to retrieve the record later, use those strings to recreate the record and zone ID objects so that you can fetch the record.
Creating Record IDs for New Records
To assign a custom record ID to a new record, you must create the
CKRecord object first. You need to know the intended name and zone information for that record, which might also require creating a
CKRecord object. After creating the record ID object, initialize your new record using its
Using Record IDs to Fetch Records
Use a record ID to fetch the corresponding
CKRecord object from a database quickly. You perform the fetch operation using a
CKFetch object or the fetchRecordWithID:completion: method of the
CKDatabase class. In both cases, the record is returned to your app asynchronously in the block you provide.