實例方法
make
makeIterator()
返回字典鍵值對的迭代器。
聲明
func makeIterator() -> Dictionary<Key, Value>.Iterator
當
Key
符合 Hashable
時可用。返回值
具有 (key: Key, value: Value)
類型元素的字典上的迭代器。
詳述
遍曆字典會產生鍵值對作為雙元素元組。您可以在 for
- in
循環中分解元組,該循環在後台調用 makeIterator()
,或者在直接調用迭代器的 next()
方法時。
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."
可用版本
iOS 8.0+, iPadOS 8.0+, macOS 10.10+, Mac Catalyst 13.0+, tvOS 9.0+, watchOS 2.0+
相關用法
- Swift Dictionary max(by:)用法及代碼示例
- Swift Dictionary map(_:)用法及代碼示例
- Swift Dictionary merge(_:uniquingKeysWith:)用法及代碼示例
- Swift Dictionary min(by:)用法及代碼示例
- Swift Dictionary merging(_:uniquingKeysWith:)用法及代碼示例
- Swift Dictionary allSatisfy(_:)用法及代碼示例
- Swift Dictionary values用法及代碼示例
- Swift Dictionary dropFirst(_:)用法及代碼示例
- Swift Dictionary firstIndex(where:)用法及代碼示例
- Swift Dictionary first(where:)用法及代碼示例
- Swift Dictionary subscript(_:default:)用法及代碼示例
- Swift Dictionary isEmpty用法及代碼示例
- Swift Dictionary reduce(_:_:)用法及代碼示例
- Swift Dictionary suffix(from:)用法及代碼示例
- Swift Dictionary subscript(_:)用法及代碼示例
- Swift Dictionary init(uniqueKeysWithValues:)用法及代碼示例
- Swift Dictionary randomElement()用法及代碼示例
- Swift Dictionary init(grouping:by:)用法及代碼示例
- Swift Dictionary dropLast(_:)用法及代碼示例
- Swift Dictionary updateValue(_:forKey:)用法及代碼示例
- Swift Dictionary removeValue(forKey:)用法及代碼示例
- Swift Dictionary forEach(_:)用法及代碼示例
- Swift Dictionary index(forKey:)用法及代碼示例
- Swift Dictionary keys用法及代碼示例
- Swift Dictionary first用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Dictionary makeIterator()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。