<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 3.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CloudKit",
  "identifier" : "/documentation/CloudKit/CKRecord/objectForKey:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "CloudKit"
    ],
    "preciseIdentifier" : "c:objc(cs)CKRecord(im)objectForKey:"
  },
  "title" : "objectForKey:"
}
-->

# objectForKey:

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

```
- (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

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

## Discussion

New records don’t contain any keys or values. Values are always one of the data types in [`Supported Data Types`](/documentation/CloudKit/CKRecord#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:`](/documentation/CloudKit/CKRecord/objectForKey:) and [`setObject:forKey:`](/documentation/CloudKit/CKRecord/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:

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

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)