我在array dictionary
中遇到循环问题。我需要这样的东西。如何检查字符串数组的项是否等于messagesDictionary
:
var stringArray = ["first","second","third"]
var messagesDictionary = [["first": 50],["second": 60],["third": 70]]
for item in stringArray {
for itemDic in messagesDictionary {
if item == itemDic[key] { // this 'itemDic[key]' wrong
}
}
}
这个循环的正确语法是什么?
答案 0 :(得分:2)
这样迭代:
let stringArray:[String] = ["first","second","third"]
let messagesDictionary: [[String: Any]] = [["first": 50],["second": 60],["third": 70]]
for item in stringArray {
for itemDic in messagesDictionary {
for (key, value) in itemDic {
if item == key {
}
}
}
}