【问题标题】:Error of "Ambiguous use of 'subscript'" shown after upgraded Xcode升级 Xcode 后显示“不明确使用 'subscript'”的错误
【发布时间】:2016-03-29 15:39:08
【问题描述】:

在我将 Xcode 升级到最新版本之后。它显示了这个错误。不知道是什么意思。

【问题讨论】:

    标签: swift subscript ios9.3


    【解决方案1】:

    ambiguous错误发生在对象类型为AnyObject且编译器不知道该对象是否可以键下标时。

    解决方案是将result 转换为合适的值。
    好像是字典

    if let dict = result as? [String:AnyObject] {
       let userId = dict["id"] as! String
       ...
    }
    

    【讨论】:

      【解决方案2】:

      您必须定义result 类型,例如,如果这是一个字典尝试:

      let dic: NSDictionary = result
      let userId: String = dic["id"] as! String
      

      【讨论】:

        猜你喜欢
        • 2012-04-25
        • 2020-09-26
        • 2022-01-10
        • 1970-01-01
        • 2019-10-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多