gpt4 book ai didi

ios 快速解析 : How to handle error codes

转载 作者:搜寻专家 更新时间:2023-10-30 22:28:43 27 4
gpt4 key购买 nike

在注册过程中,用户可能会导致一些错误,例如用户名已被占用,电子邮件地址无效等...

Parse 在错误对象中返回所有需要的信息,参见 http://parse.com/docs/dotnet/api/html/T_Parse_ParseException_ErrorCode.htm

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

                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)
}
}

如何切换可能的错误代码编号?请指教谢谢!

最佳答案

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

关于ios 快速解析 : How to handle error codes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28607012/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com