Sets the value for the specified key.
- iOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 3.0+
The value to assign to the specified
key. The object must be one of the types listed in Supported Data Types. It is a programmer error to specify an object of any other type. Specify
nilfor this parameter to remove the value for the field.
The key to associate with
obj. Use this key to retrieve the value later. 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. The names of your keys must not match the names of any properties of this class.
If the specified key already exists in the record, its old value is deleted and replaced with the one in the
obj parameter. This change affects only the local copy of the record. You must save the record to the server again before the change becomes available to other clients.
If the type of the
obj parameter differs from the type of the object currently saved on the server, you will encounter an error when you attempt to save this record to the server. For example, if the current value is an
NSString object, you will get an error if you change the value to an
NSNumber object and save the record.
You access the fields of a
CKRecord object the same way you access key-value pairs in an
CKRecord class defines the
set 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
first and get a field named
last from a given record.