【发布时间】:2015-06-17 22:42:46
【问题描述】:
我将 Xcode 更新到 6.3,发现新的 Swift 1.2 代码中出现了一些新错误。
user.signUpInBackgroundWithBlock {
(success:Bool!, error:NSError!) -> Void in
if !(error != nil) {
println("sign up successfully")
var loginAlert: UIAlertController = UIAlertController(title: "Sign Up", message: "Sign Up Succeeded", preferredStyle: UIAlertControllerStyle.Alert)
self.presentViewController(loginAlert, animated: true, completion: nil)
loginAlert.addAction(UIAlertAction(title: "Okay", style:
我收到了这个错误:
无法使用类型为 ((Bool!, NSError!) -> void) 的参数列表调用 signUpInBackgroundWithBlock
我该如何解决?
另一个
@IBAction func endend(sender: AnyObject) {
if (PFUser.currentUser() == nil) {
PFUser.logInWithUsernameInBackground(usernameTextField.text, password: passwordTextField.text){
(user:PFUser!, error:NSError!) -> Void in
if user != nil {
println("login chenggong")
var tlvc = TimelineViewControllerTableViewController()
self.presentViewController(tlvc, animated: true, completion: nil)
}
else {
println("failed")
}
}
}
}
我收到了这个错误:
“UITextField”没有名为“text”的成员。
我收到了 3 个关于 } 的错误,上面写着
预期的“,”分隔符。
表达式列表中的预期表达式。
表达式中应为“)”。
我可以在 Swift 1.2 之前运行我的应用,但现在...
【问题讨论】:
-
if !(error != nil)写成if error == nil更合理,你能告诉我们signUpInBackgroundWithBlock方法的声明吗? -
用户名后面缺少冒号
-
我找不到你刚才提到的用户名。但是感谢您的帮助!
标签: swift objective-c-nullability