简体   繁体   中英

xcode 8 value of type 'Error' has no member 'userinfo'

I just upgraded to Xcode 8 and am already getting errors which cause the build to fail. I'm very new to swift, please help.

在此处输入图片说明

What should I change this to? Thanks

UPDATE

Apart from this error i also got the following:

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)

                    }
                })

for the // line I got "type NSError has no subscript members" error. I tried bridging it to NSError but it does not work this time. What should i do? thanks a lot

First of all, post the code (text) rather than a screenshot.

In Swift 3 NSError has been replaced in many APIs with more generic Swift Error protocol which has no userInfo dictionary. Bridge cast the object to NSError

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

我发现这有效

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM