Instance Method

objectForKey:

Returns the value for the given key stored in the record.

Declaration

- (id<CKRecordValue>)objectForKey:(CKRecordFieldKey)key;

Parameters

key

The string that identifies a field in the record. Key names consist of one or more alphanumeric characters and start with a letter. You may also include underscore characters if you do not use an underscore as the first character in the name. Spaces are not allowed in key names.

Return Value

The object associated with the specified key or nil if no such key exists in the record.

Discussion

New records do not contain any keys or values initially. Values are always one of the object types listed in Supported Data Types.

You access the fields of a CKRecord object the same way you access key-value pairs in an NSMutableDictionary. The CKRecord class defines the objectForKey: and setObject:forKey: methods for getting and setting values. It also supports dictionary index notation. The following example shows how to use both techniques to set a field named firstName and get a field named lastName from a given record.

// Equivalent ways to get a value.
id value = [myRecord objectForKey:@"hiredAt"];
value = myRecord[@"hiredAt"];

See Also

Accessing the Record’s Fields

- setObject:forKey:

Sets the value for the specified key.

- objectForKeyedSubscript:

Returns the value for the given key stored in the record.

- setObject:forKeyedSubscript:

Adds the specified key-value pair to the record.

- allKeys

Returns an array of strings corresponding to all keys currently in the record.

- changedKeys

Returns an array of strings representing the keys that have changed recently.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software