Subscript

subscript(_:)

Returns the value associated with a given key.

Declaration

subscript(key: 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:) 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"]

See Also

Accessing Keys and Values

var allKeys: [Any]

A new array containing the dictionary’s keys, or an empty array if the dictionary has no entries.

func allKeys(for: Any) -> [Any]

Returns a new array containing the keys corresponding to all occurrences of a given object in the dictionary.

var allValues: [Any]

A new array containing the dictionary’s values, or an empty array if the dictionary has no entries.

func value(forKey: String) -> Any?

Returns the value associated with a given key.

func objects(forKeys: [Any], notFoundMarker: Any) -> [Any]

Returns as a static array the set of objects from the dictionary that corresponds to the specified keys.

func object(forKey: Any) -> Any?

Returns the value associated with a given key.

subscript(Any) -> Any?

Accesses the value associated with a given key.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software