<!--
{
  "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/subscript(_:)-52n56",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDictionary(im)objectForKeyedSubscript:"
  },
  "title" : "subscript(_:)"
}
-->

# subscript(_:)

Returns the value associated with a given key.

```
subscript(key: any NSCopying) -> Any? { get }
```

## Parameters

`key`

The key for which to return the corresponding value.

## Return Value

The value associated with `key`, or `nil` if no value is associated with `aKey`.

## Discussion

This method has the same behavior as the [`object(forKey:)`](/documentation/Foundation/NSDictionary/object(forKey:)) method.

You shouldn’t need to call this method directly. Instead, this method is called when accessing an object by key using subscripting.

```objc
id value = dictionary[@"key"]; // equivalent to [dictionary objectForKeyedSubscript:@"key"]
```

## See Also

[`-  setObject:forKeyedSubscript:`](/documentation/Foundation/NSMutableDictionary/setObject:forKeyedSubscript:)

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)