【发布时间】:2015-11-23 13:14:27
【问题描述】:
我有两个字典,看起来像:
var dict1 = [Int: [String: AnyObject]]
var dict2 = [Int: [String: AnyObject]]
例如:
dict1: [0: ["sender": "user1", "time": NSDate(), "mId": "as2f2ASf"], [1: ["sender": "user1", "time": NSDate(), "mId": "Sjf82FsJ"]
dict2: [0: ["sender": "user2", "time": NSDate(), "mId": "J2fAS92D"], [1: ["sender": "user2", "time": NSDate(), "mId": "Sjf82FsJ"]
我想知道字典中是否有具有相同 mId 的数据,如果我想执行一些操作。 我为此编写了这段代码并得到了这些错误。
for (_, value) in dict1! {
for content in value {
if content.0 == "mId" {
var mID = content.1
for (_, 2ndValue) in dict2 {
for 2ndContent in 2ndValue {
if 2ndContent.0 == "mId" {
var 2ndMID = 2ndContent.1
if mID == 2ndMID {
//Do Some Action
}
}
}
}
}
}
}
以下是错误: https://www.dropbox.com/s/e28ple6640hkrzo/Bildschirmfoto%202015-08-28%20um%2021.21.54.png?dl=0
【问题讨论】:
-
有很多语法错误,我不确定像
arr这样的东西来自哪里。话虽如此,您的直接错误是因为您不能以数字开头的变量名。 -
哦 - 通常我不会那样做,但我想,如果 var 可以是笑脸,它也可以以数字开头
标签: ios swift dictionary swift2