---
title: keys
framework: swift
role: symbol
role_heading: Instance Property
path: swift/dictionary/keys-swift.property
---

# keys

A collection containing just the keys of the dictionary.

## Declaration

```swift
var keys: Dictionary<Key, Value>.Keys { get }
```

## Discussion

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"

## See Also

### Accessing Keys and Values

- [subscript(_:)](swift/dictionary/subscript(_:)-8rfql.md)
- [subscript(_:default:)](swift/dictionary/subscript(_:default:).md)
- [index(forKey:)](swift/dictionary/index(forkey:).md)
- [subscript(_:)](swift/dictionary/subscript(_:)-4bhoo.md)
- [values](swift/dictionary/values-swift.property.md)
- [first](swift/dictionary/first.md)
- [randomElement()](swift/dictionary/randomelement().md)
- [randomElement(using:)](swift/dictionary/randomelement(using:).md)
