---
title: "setObject:forKeyedSubscript:"
framework: cloudkit
role: symbol
role_heading: Instance Method
path: "cloudkit/ckrecord/setobject:forkeyedsubscript:"
---

# setObject:forKeyedSubscript:

Stores an object in the record using the specified key.

## Declaration

```occ
- (void) setObject:(id<CKRecordValue>) object forKeyedSubscript:(CKRecordFieldKey) key;
```

## Parameters

- `object`: The object to store using the specified key. It must be one of the data types in doc://com.apple.cloudkit/documentation/CloudKit/CKRecord#Supported-Data-Types. You receive an error if you use a data type that CloudKit doesn’t support. If you specify nil, CloudKit removes any object that the record associates with the key.
- `key`: The key to associate with object. Use this key to retrieve the value later. A key must consist of one or more alphanumeric characters and must start with a letter. CloudKit permits the use of underscores, but not spaces. Avoid using a key that matches the name of any property of CKRecord.

## Discussion

Discussion important: Don’t call this method directly. The presence of this method is necessary to support subscripting syntax for record objects.

## See Also

### Accessing the Record’s Fields

- [objectForKey:](cloudkit/ckrecord/objectforkey:.md)
- [subscript(_:)](cloudkit/ckrecord/subscript(_:)-51whk.md)
- [setObject:forKey:](cloudkit/ckrecord/setobject:forkey:.md)
- [allKeys](cloudkit/ckrecord/allkeys.md)
- [changedKeys](cloudkit/ckrecord/changedkeys.md)
- [CKRecordKeyValueSetting](cloudkit/ckrecordkeyvaluesetting.md)
- [CKRecordCreationDateKey](cloudkit/ckrecordcreationdatekey.md)
- [CKRecordCreatorUserRecordIDKey](cloudkit/ckrecordcreatoruserrecordidkey.md)
- [CKRecordLastModifiedUserRecordIDKey](cloudkit/ckrecordlastmodifieduserrecordidkey.md)
- [CKRecordModificationDateKey](cloudkit/ckrecordmodificationdatekey.md)
- [CKRecordRecordIDKey](cloudkit/ckrecordrecordidkey.md)
- [CKRecordParentKey](cloudkit/ckrecordparentkey-2kx8l.md)
- [CKRecordShareKey](cloudkit/ckrecordsharekey-rrat.md)
