[NSObject : AnyObject]?' does not have a member named 'subscript' in Xcode 6 Beta 6

前端 未结 1 1765
庸人自扰
庸人自扰 2021-02-08 11:13

I am building an app in Xcode 6 Beta 6 in Swift and I keep getting this error:

[NSObject : AnyObject]?\' does not have a member named \'subscript\'
相关标签:
1条回答
  • 2021-02-08 11:43

    The error message is saying you can't do [] on Optional value. What you need to do is unwrap it.

    error.userInfo!["error"] as NSString
    

    or if you want to be safe

    if let errorString = error.userInfo?["error"] as NSString {
         println(errorString)
    }
    
    0 讨论(0)
提交回复
热议问题