实例方法
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()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。