xcode 8类型'Error'的值没有成员'userinfo'

时间:2016-09-21 12:54:48

标签: ios swift xcode8

我刚刚升级到Xcode 8并且我已经收到导致构建失败的错误。我很快乐,请帮忙。

enter image description here

我应该将此更改为什么?感谢

更新

除了这个错误,我还得到了以下内容:

PFUser.logInWithUsername(inBackground: usernameTextField.text!, password: passwordTextField.text!, block: { (user, error) -> Void in

                    //self.activityIndicator.stopAnimating()
                    UIApplication.shared.endIgnoringInteractionEvents()

                    if user != nil {

                        self.launchDrawerMenu()

                    } else {

                        let convertedError = error! as NSError

                        //if let errorString = convertedError["error"] as? String {
                            errorMessage = errorString
                        }
                        self.displayAlert("Login failed", message: errorMessage)

                    }
                })

对于//我得到的“类型NSError没有下标成员”错误。我尝试将它桥接到NSError,但这次它不起作用。我该怎么办?非常感谢

2 个答案:

答案 0 :(得分:30)

首先,发布代码(文本)而不是截图。

在Swift 3中NSError已被许多API替换为更通用的Swift Error协议,该协议没有userInfo字典。 Bridge将对象强制转换为NSError

if let errorString = (error! as NSError).userInfo....

答案 1 :(得分:0)

我发现这很有用

let errorUserInfo : NSDictionary? = ((error as Any) as! NSError).userInfo["error"] as? NSDictionary