Contents

initWithRecordType:

Creates a new record of the specified type.

Declaration

- (instancetype) initWithRecordType:(CKRecordType) recordType;

Parameters

  • recordType:

    A string that represents the type of record that you want to create. You can’t change the record type after initialization. You define the record types that your app supports and use them to distinguish between records with different types of data. This parameter must not be nil or contain an empty string.

    A record type must consist of one or more alphanumeric characters and must start with a letter. CloudKit permits the use of underscores, but not spaces.

Mentioned in

Return Value

An initialized record object.

Discussion

Use this method to initialize a new record object in the default zone of the database. The newly created record contains no data in any of its fields and receives a unique ID.

// Create a new record of type "employee".
CKRecord* myRecord = [[CKRecord alloc] initWithRecordType:@"employee"];

New records exist only in memory until you explicitly save them to iCloud. In addition, new records are sparse by default and have no values for the fields you define. Until you set the value of a key explicitly, getting the value of a key in a new record returns nil. Even though a record has an associated type, CloudKit ignores the type information until you save the record.

Save the record using a CKModifyRecordsOperation object or by using the save(_:completionHandler:) method of CKDatabase to transfer the record’s contents to the server.

See Also

Creating a Record