【问题标题】:Ambiguous use of subscript when attempting to use physical simulator尝试使用物理模拟器时使用不明确的下标
【发布时间】:2017-03-22 18:10:47
【问题描述】:

我正在尝试在物理设备 (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! [字符串:AnyObject]

Image of error message within code.

【问题讨论】:

    标签: ios xcode swift3 ios-simulator ambiguous


    【解决方案1】:

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

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

    AnyObject 将是数组内容的类型。

    【讨论】:

      猜你喜欢
      • 2016-05-18
      • 2016-09-11
      • 1970-01-01
      • 2013-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 1970-01-01
      相关资源
      最近更新 更多