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

# value(forKey:)

Returns the value associated with a given key.

## Declaration

```swift
func value(forKey key: String) -> Any?
```

## Parameters

- `key`: The key for which to return the corresponding value. Note that when using key-value coding, the key must be a string (see https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/KeyValueCoding/BasicPrinciples.html#//apple_ref/doc/uid/20002170).

## Return Value

Return Value The value associated with key.

## Discussion

Discussion If key does not start with “@”, invokes object(forKey:). If key does start with “@”, strips the “@” and invokes [super valueForKey:] with the rest of the key.

## See Also

### Related Documentation

- [setValue(_:forKey:)](foundation/nsmutabledictionary/setvalue(_:forkey:).md)

### Accessing Keys and Values

- [allKeys](foundation/nsdictionary/allkeys.md)
- [allKeys(for:)](foundation/nsdictionary/allkeys(for:).md)
- [allValues](foundation/nsdictionary/allvalues.md)
- [objects(forKeys:notFoundMarker:)](foundation/nsdictionary/objects(forkeys:notfoundmarker:).md)
- [object(forKey:)](foundation/nsdictionary/object(forkey:).md)
- [subscript(_:)](foundation/nsdictionary/subscript(_:)-52n56.md)
- [subscript(_:)](foundation/nsdictionary/subscript(_:)-1bt1b.md)
