Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

swift

xcode8

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

like image 203
H. Lamb Avatar asked Sep 21 '16 12:09

H. Lamb


1 Answers

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....
like image 71
vadian Avatar answered Oct 23 '22 08:10

vadian