<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSDictionary/value(forKey:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDictionary(im)valueForKey:"
  },
  "title" : "value(forKey:)"
}
-->

# value(forKey:)

Returns the value associated with a given key.

```
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 [Accessing Object Properties](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/KeyValueCoding/BasicPrinciples.html#//apple_ref/doc/uid/20002170)).

## Return Value

The value associated with `key`.

## Discussion

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

## See Also

[`getObjects:andKeys:`](/documentation/Foundation/NSDictionary/getObjects:andKeys:)

Returns by reference C arrays of the keys and values in the dictionary.

[`setValue(_:forKey:)`](/documentation/Foundation/NSMutableDictionary/setValue(_:forKey:))

Adds a given key-value pair to the dictionary.



---

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)