description
A string that represents the contents of the dictionary.
var description: String { get }
A string that represents the contents of the dictionary.
var description: String { get }
where Key:Hashable
import Swift
@frozen struct Dictionary<Key, Value> where Key : Hashable
A collection whose elements are key-value pairs.
@frozen struct String
A Unicode string value that is a collection of characters.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
init(dictionaryLiteral elements: (Key, Value)...)
Creates a dictionary initialized with a dictionary literal.
var capacity: Int { get }
The total number of key-value pairs that the dictionary can contain without allocating new storage.
var count: Int { get }
The number of key-value pairs in the dictionary.
var customMirror: Mirror { get }
A mirror that reflects the dictionary.
var debugDescription: String { get }
A string that represents the contents of the dictionary, suitable for debugging.
var endIndex: Dictionary<Key, Value>.Index { get }
The dictionary’s “past the end” position—that is, the position one greater than the last valid subscript argument.
var isEmpty: Bool { get }
A Boolean value that indicates whether the dictionary is empty.
var keys: Dictionary<Key, Value>.Keys { get }
A collection containing just the keys of the dictionary.
var startIndex: Dictionary<Key, Value>.Index { get }
The position of the first element in a nonempty dictionary.
var values: Dictionary<Key, Value>.Values { get set }
A collection containing just the values of the dictionary.
subscript(key: Key) -> Value? { get set }
Accesses the value associated with the given key for reading and writing.
subscript(position: Dictionary<Key, Value>.Index) -> Dictionary<Key, Value>.Element { get }
Accesses the key-value pair at the specified position.
subscript(key: Key, default defaultValue: @autoclosure () -> Value) -> Value { get set }
Accesses the value with the given key, falling back to the given default value if the key isn’t found.
func compactMapValues<T>(_ transform: (Value) throws -> T?) rethrows -> Dictionary<Key, T>
Returns a new dictionary containing only the key-value pairs that have non-nil
values as the result of transformation by the given closure.
func filter(_ isIncluded: (Dictionary<Key, Value>.Element) throws -> Bool) rethrows -> [Key : Value]
Returns a new dictionary containing the key-value pairs of the dictionary that satisfy the given predicate.
func formIndex(after i: inout Dictionary<Key, Value>.Index)
func index(after i: Dictionary<Key, Value>.Index) -> Dictionary<Key, Value>.Index
func index(forKey key: Key) -> Dictionary<Key, Value>.Index?
Returns the index for the given key.
func makeIterator() -> Dictionary<Key, Value>.Iterator
Returns an iterator over the dictionary’s key-value pairs.
func mapValues<T>(_ transform: (Value) throws -> T) rethrows -> Dictionary<Key, T>
Returns a new dictionary containing the keys of this dictionary with the values transformed by the given closure.
mutating func merge(_ other: [Key : Value], uniquingKeysWith combine: (Value, Value) throws -> Value) rethrows
Merges the given dictionary into this dictionary, using a combining closure to determine the value for any duplicate keys.
mutating func merge<S>(_ other: S, uniquingKeysWith combine: (Value, Value) throws -> Value) rethrows where S : Sequence, S.Element == (Key, Value)
Merges the key-value pairs in the given sequence into the dictionary, using a combining closure to determine the value for any duplicate keys.
func merging(_ other: [Key : Value], uniquingKeysWith combine: (Value, Value) throws -> Value) rethrows -> [Key : Value]
Creates a dictionary by merging the given dictionary into this dictionary, using a combining closure to determine the value for duplicate keys.
func merging<S>(_ other: S, uniquingKeysWith combine: (Value, Value) throws -> Value) rethrows -> [Key : Value] where S : Sequence, S.Element == (Key, Value)
Creates a dictionary by merging key-value pairs in a sequence into the dictionary, using a combining closure to determine the value for duplicate keys.
mutating func popFirst() -> Dictionary<Key, Value>.Element?
Removes and returns the first key-value pair of the dictionary if the dictionary isn’t empty.
@discardableResult mutating func remove(at index: Dictionary<Key, Value>.Index) -> Dictionary<Key, Value>.Element
Removes and returns the key-value pair at the specified index.
mutating func removeAll(keepingCapacity keepCapacity: Bool = false)
Removes all key-value pairs from the dictionary.
@discardableResult mutating func removeValue(forKey key: Key) -> Value?
Removes the given key and its associated value from the dictionary.
mutating func reserveCapacity(_ minimumCapacity: Int)
Reserves enough space to store the specified number of key-value pairs.
@discardableResult mutating func updateValue(_ value: Value, forKey key: Key) -> Value?
Updates the value stored in the dictionary for the given key, or adds a new key-value pair if the key does not exist.
@frozen struct Index
The position of a key-value pair in a dictionary.
@frozen struct Iterator
An iterator over the members of a Dictionary<Key, Value>
.
@frozen struct Keys
A view of a dictionary’s keys.
@frozen struct Values
A view of a dictionary’s values.
typealias SubSequence = Slice<Dictionary<Key, Value>>