Dictionary API Reference
Swift's Dictionary<K, V> — a collection of unique keys mapped to values, with O(1) average lookup.
Dictionary
A collection whose elements are key-value pairs. A value type bridged to NSDictionary.
Dictionary subscript [Key] -> Value?Accesses the value associated with the given key, returning nil if the key is not present.
Returns: Value?
Dictionary.count -> IntThe number of key-value pairs in the dictionary.
Returns: Int
Dictionary.keys -> Dictionary.KeysA collection containing just the keys of the dictionary.
Returns: Dictionary.Keys
Dictionary.values -> Dictionary.ValuesA collection containing just the values of the dictionary.
Returns: Dictionary.Values
Dictionary.updateValue(_ value: Value, forKey key: Key) -> Value?Updates the value for the given key, returning the old value (or nil if key was new).
Returns: Value?
Dictionary.removeValue(forKey: Key) -> Value?Removes the given key and its associated value, returning the removed value (or nil).
Returns: Value?
Dictionary.forEach(_ body: ((key: Key, value: Value)) throws -> Void) rethrowsCalls the given closure on each key-value pair in the dictionary.
Returns: Void