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

# object(forKey:)

Returns the value associated with a given key.

## Declaration

```swift
func object(forKey key: KeyType) -> ObjectType?
```

## Parameters

- `key`: An object identifying the value.

## Return Value

Return Value The value associated with key, or nil if no value is associated with key.

## See Also

### Related Documentation

- [removeObject(forKey:)](foundation/nscache/removeobject(forkey:).md)
- [setObject(_:forKey:cost:)](foundation/nscache/setobject(_:forkey:cost:).md)
- [setObject(_:forKey:)](foundation/nscache/setobject(_:forkey:).md)
