H. Lamb H. Lamb - 2 months ago 74
Swift Question

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.

enter image description here

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

Answer

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

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

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