ios swift parse: How to handle error codes

ios, parse-platform, swift

Solution

An `NSError` also has a property called `code`. That code contains the error-code you need. So you can make a switch-statement with that code:

user.signUpInBackgroundWithBlock {
    (succeeded: Bool!, error: NSError!) -> Void in
    if error == nil {
        // Hooray! Let them use the app now.
        self.updateLabel("Erfolgreich registriert")
    } else {
        println(error.userInfo)
        var errorCode = error.code

        switch errorCode {
        case 100:
            println("ConnectionFailed")
            break
        case 101:
            println("ObjectNotFound")
            break
        default:
            break
        }
    }
}

Problem

While on a signup process, the user can cause several errors like Username already taken, invalid email address etc... Parse returns within the error object all needed infos see http://parse.com/docs/dotnet/api/html/T_Parse_ParseException_ErrorCode.htm What I can't find out is how to use them eg how to access them in order to write a switch to catch all possibilities: ``` user.signUpInBackgroundWithBlock { (succeeded: Bool!, error: NSError!) -> Void in if error == nil { // Hooray! Let them use the app now. self.updateLabel("Erfolgreich registriert") } else { println(error.userInfo) } } ``` What can I do to switch through the possible error code numbers? Please advice Thanks!

Original source