在Swift 4中,下面的代码可以工作,但是在Swift 5中,出现以下错误: Type 'Dictionary<String, String>.Values.Iterator' does not conform to protocol 'Sequence'
guard let userIds = users.values.makeIterator() else { return }
for userId in userIds {
// User setup
}
Run Code Online (Sandbox Code Playgroud)
Swift 5现在正确的方法是什么?
let dictionary: [String: Int] = ["a": 1, "b": 2]
for (key, value) in dictionary {
print(key, value)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
443 次 |
| 最近记录: |