A collection containing just the keys of the dictionary.
SDK
- Xcode 9.0+
Framework
- Swift Standard Library
Declaration
var keys: Dictionary<Key, Value>.Keys { get }
Discussion
When iterated over, keys appear in this collection in the same order as they occur in the dictionary’s key-value pairs. Each key in the keys collection has a unique value.
let countryCodes = ["BR": "Brazil", "GH": "Ghana", "JP": "Japan"]
print(countryCodes)
// Prints "["BR": "Brazil", "JP": "Japan", "GH": "Ghana"]"
for k in countryCodes.keys {
print(k)
}
// Prints "BR"
// Prints "JP"
// Prints "GH"