Ios swift parse: How to handle error codes

During the registration process, the user may cause several errors, for example, the username has already been made, an invalid email address, etc.

Parse returns inside the error object all the necessary information, see http://parse.com/docs/dotnet/api/html/T_Parse_ParseException_ErrorCode.htm

I can’t find out how to use them, for example, how to contact them to write a switch to catch all the 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 possible error codes? Please advise Thank you!

+4
source share
3 answers

An NSError code. , . switch :

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
        }
    }
}
+8

, -

if let error = error,let code = PFErrorCode(rawValue: error._code) {
    switch code {
    case .errorConnectionFailed:
        print("errorConnectionFailed")
    case .errorObjectNotFound:
        print("errorObjectNotFound")
    default:
        break
    }
}

: https://github.com/parse-community/Parse-SDK-iOS-OSX/blob/master/Parse/PFConstants.h#L128

+1

You can also use PFErrorCode:

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 PFErrorCode.ErrorConnectionFailed.rawValue:
              println("ConnectionFailed")
           case PFErrorCode.ErrorObjectNotFound.rawValue:
              println("ObjectNotFound")
           default:
              break
        }
    }
}
0
source

All Articles