subscript(_:)
Returns the value associated with a given key.
Declaration
subscript(key: any NSCopying) -> Any? { get }subscript(key: any NSCopying) -> Any? { get set }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:) method.
You shouldn’t need to call this method directly. Instead, this method is called when accessing an object by key using subscripting.
id value = dictionary[@"key"]; // equivalent to [dictionary objectForKeyedSubscript:@"key"]