Swift 1.2的变化让我困惑
我将Xcode更新为6.3,发现使用新的Swift 1.2时代码中出现了一些新错误Swift 1.2的变化让我困惑,swift,objective-c-nullability,Swift,Objective C Nullability,我将Xcode更新为6.3,发现使用新的Swift 1.2时代码中出现了一些新错误 user.signUpInBackgroundWithBlock { (success:Bool!, error:NSError!) -> Void in if !(error != nil) { println("sign up successfully") var loginAlert: UIAlertController = UI
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的参数列表调用SignupInBackgroundithBlock
我怎样才能修好它
另一个
@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之前运行我的应用程序,但现在…在Xcode中,转到编辑>转换…>到最新的Swift语法
新版本中有一些语言语法变化,因此苹果公司提供了一个工具来帮助迁移较旧的Swift代码。从我所读到的内容来看,它在很大程度上是有用的,但并不总能解决100%的问题。希望它至少能减少您看到的错误数量。对于解析注册块,当您强制展开布尔成功参数时,Swift 1.2编译器不喜欢它 删除“!”在“success:Bool”之后,应该删除您得到的错误 尝试更改:
user.signUpInBackgroundWithBlock{(success:Bool!, error:NSError!) -> Void in
user.signUpInBackgroundWithBlock{(success:Bool!, error:NSError!) -> Void in
致:
以下代码适用于我:
PFUser.logInWithUsernameInBackground(username.text as String!, password: password.text as String!){
(loggedInuser: PFUser?, signupError: NSError?) -> Void in
尝试更改:
致:
if!(error!=nil)
写得更合理,因为如果error==nil
你能给我们看一下signUpInBackgroundWithBlock
方法的声明吗?你在用户名后面缺少冒号我找不到你刚才提到的用户名。但是谢谢你的帮助!
user.signUpInBackgroundWithBlock{(success:Bool!, error:NSError!) -> Void in
user.signUpInBackgroundWithBlock{(success:Bool?, error:NSError?) -> Void in