在尝试使用物理模拟器时模糊地使用下标

时间:2017-03-22 18:10:48

标签: ios xcode swift3 ios-simulator ambiguous

我正在尝试在物理设备(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?
            }
        }

我收到以下行的错误:让aObject = array [index]为! [String:AnyObject]

Image of error message within code.

1 个答案:

答案 0 :(得分:0)

这是因为swift不确定if let array = allUsers["user_info"]中的数组数组。您可以像下面一样投射它,它不应该抱怨:

if let array = allUsers["user_info"] as? [AnyObject] {
    //you code
}

AnyObject 将是您阵列内容的类型。