Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios swift解析:如何处理错误代码_Ios_Swift_Parse Platform - Fatal编程技术网

ios swift解析:如何处理错误代码

ios swift解析:如何处理错误代码,ios,swift,parse-platform,Ios,Swift,Parse Platform,在注册过程中,用户可能会导致以下错误: 用户名已被占用,电子邮件地址无效等 Parse在error对象中返回所有需要的信息请参见 我找不到的是如何使用它们,例如如何访问它们,以便编写一个开关来捕获所有可能性: user.signUpInBackgroundWithBlock { (succeeded: Bool!, error: NSError!) -> Void in if e

在注册过程中,用户可能会导致以下错误: 用户名已被占用,电子邮件地址无效等

Parse在error对象中返回所有需要的信息请参见

我找不到的是如何使用它们,例如如何访问它们,以便编写一个开关来捕获所有可能性:

                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)
                    }
                }
如何切换可能的错误代码? 请指教
谢谢

一个
n错误
还有一个名为的属性。该代码包含您需要的错误代码。因此,您可以使用该代码生成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
        }
    }
}

您也可以使用
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
        }
    }
}

嗨,我想做点什么

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

这里有完整的错误列表:

当然,没问题!完成:-)有没有办法使用常量?我真的不喜欢硬编码值…@TakeshiKaga是的,你可以,例如:
case-nsurerrorcannotconnecttohost: