---
title: "objectForKey:"
framework: cloudkit
role: symbol
role_heading: Instance Method
path: "cloudkit/ckrecord/objectforkey:"
---

# objectForKey:

Returns the object that the record stores for the specified key.

## Declaration

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

## Parameters

- `key`: The string that identifies a field in the record. 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.

## Return Value

Return Value The object for the specified key, or nil if no such key exists in the record.

## Discussion

Discussion New records don’t contain any keys or values. Values are always one of the data types in Supported Data Types. You access the fields of a CKRecord object the same way you access key-value pairs in a dictionary. 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 firstName field and retrieve a lastName field from a record: // Equivalent ways to get a value. id value = [myRecord objectForKey:@"hiredAt"]; value = myRecord[@"hiredAt"];

## See Also

### Accessing the Record’s Fields

- [subscript(_:)](cloudkit/ckrecord/subscript(_:)-51whk.md)
- [setObject:forKey:](cloudkit/ckrecord/setobject:forkey:.md)
- [setObject:forKeyedSubscript:](cloudkit/ckrecord/setobject:forkeyedsubscript:.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)
