---
title: "object(forKey:)"
framework: cloudkit
role: symbol
role_heading: Instance Method
path: "cloudkit/ckrecordkeyvaluesetting/object(forkey:)"
---

# object(forKey:)

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

## Declaration

```swift
func object(forKey key: String) -> (any __CKRecordObjCValue)?
```

## 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.

## See Also

### Accessing a Record’s Fields

- [subscript(_:)](cloudkit/ckrecordkeyvaluesetting/subscript(_:).md)
- [setObject(_:forKey:)](cloudkit/ckrecordkeyvaluesetting/setobject(_:forkey:).md)
- [allKeys()](cloudkit/ckrecordkeyvaluesetting/allkeys().md)
- [changedKeys()](cloudkit/ckrecordkeyvaluesetting/changedkeys().md)
