尝试使用物理模拟器时下标使用不明确
Ambiguous use of subscript when attempting to use physical simulator
我正在尝试 运行 我的应用程序在物理设备 (iPhone 6+) 上运行,但我不断收到此错误消息。 下标使用不明确。 运行在模拟器上运行应用程序时一切正常运行,我想知道这是否是与使用物理设备相对应的问题。
//Making array to sort through the index of the specific field
if let array = allUsers["user_info"] {
for index in 0...array.count-1 {
let aObject = array[index] as! [String : AnyObject]
let Emails = aObject["email"] as! String
let Passwords = aObject["password"] as! String
user_info[Emails] = Passwords as AnyObject?
}
}
我在以下行收到错误:let aObject = array[index] as! [字符串:任何对象]
Image of error message within code.
那是因为 swift 不确定 if let array = allUsers["user_info"]
中的 array 是 array 。你可以像下面这样投射它,它不应该抱怨:
if let array = allUsers["user_info"] as? [AnyObject] {
//you code
}
AnyObject 将是数组内容的类型。
我正在尝试 运行 我的应用程序在物理设备 (iPhone 6+) 上运行,但我不断收到此错误消息。 下标使用不明确。 运行在模拟器上运行应用程序时一切正常运行,我想知道这是否是与使用物理设备相对应的问题。
//Making array to sort through the index of the specific field
if let array = allUsers["user_info"] {
for index in 0...array.count-1 {
let aObject = array[index] as! [String : AnyObject]
let Emails = aObject["email"] as! String
let Passwords = aObject["password"] as! String
user_info[Emails] = Passwords as AnyObject?
}
}
我在以下行收到错误:let aObject = array[index] as! [字符串:任何对象]
Image of error message within code.
那是因为 swift 不确定 if let array = allUsers["user_info"]
中的 array 是 array 。你可以像下面这样投射它,它不应该抱怨:
if let array = allUsers["user_info"] as? [AnyObject] {
//you code
}
AnyObject 将是数组内容的类型。