An object that uniquely identifies a record in a database.


class ID : NSObject


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 CKRecordID 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 CKRecord.Reference 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 CKRecordID and CKRecordZone.ID 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 CKRecordID object first. You need to know the intended name and zone information for that record, which might also require creating a CKRecordZone.ID object. After creating the record ID object, initialize your new record using its init(__recordType:recordID:) method.

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 CKFetchRecordsOperation 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.


Initializing a Record ID

init(recordName: String)

Initializes and returns a new record ID with the specified name in the default zone.

Getting the Name and Zone

var recordName: String

The unique name of the record.

var zoneID: CKRecordZone.ID

The ID of the zone containing the record.


Inherits From

See Also

Accessing the Record’s Metadata

var recordID: CKRecord.ID

The unique ID of the record.

var creationDate: Date?

The time when the record was first saved to the server.

var creatorUserRecordID: CKRecord.ID?

The ID of the user who created the record.

var modificationDate: Date?

The time when the record was last saved to the server.

var lastModifiedUserRecordID: CKRecord.ID?

The ID of the user who last modified the record.

var recordChangeTag: String?

A string containing the server change token for the record.