Returns an iterator over the dictionary’s key-value pairs.
SDK
- Xcode 10.2+
Framework
- Swift Standard Library
Declaration
func makeIterator() -> Dictionary<Key, Value>.Iterator
Return Value
An iterator over the dictionary with elements of type (key: Key, value: Value)
.
Discussion
Iterating over a dictionary yields the key-value pairs as two-element tuples. You can decompose the tuple in a for
-in
loop, which calls make
behind the scenes, or when calling the iterator’s next()
method directly.
let hues = ["Heliotrope": 296, "Coral": 16, "Aquamarine": 156]
for (name, hueValue) in hues {
print("The hue of \(name) is \(hueValue).")
}
// Prints "The hue of Heliotrope is 296."
// Prints "The hue of Coral is 16."
// Prints "The hue of Aquamarine is 156."