swift - Swift 1.2 中让我困惑的变化

标签 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 = UIAlertController(title: "Sign Up", message: "Sign Up Succeeded", preferredStyle: UIAlertControllerStyle.Alert)
        self.presentViewController(loginAlert, animated: true, completion: nil)
        loginAlert.addAction(UIAlertAction(title: "Okay", style:

我遇到了这个错误:

Cannot invoke signUpInBackgroundWithBlock with an argument list of type ((Bool!, NSError!) -> void)

我该如何解决?

另一个

@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” does not have member named “text”.

关于 我有 3 个错误,它说

Expected “,” separator.

Expected expression in list of expressions.

Expected “)” in expressions.

我可以在 Swift 1.2 之前运行我的应用程序,但现在...

最佳答案

以下代码对我有用:

PFUser.logInWithUsernameInBackground(username.text as String!, password: password.text as String!){
                (loggedInuser: PFUser?, signupError: NSError?) -> Void in

关于swift - Swift 1.2 中让我困惑的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29591482/

相关文章:

objective-c - Objective-C 中可为空、__nullable 和 _Nullable 之间的区别

swift - 如何在 Swift 4 中使用 #selector() 处理 @objc 推理弃用?

ios - 尝试以编程方式更改其高度后,UITextView 不会更新其高度

ios - 如何在 Swift 中以编程方式将设备方向添加到项目中?

macos - Cocoa Storyboard 响应链

ios - 如何在 Objective-C 中安全地将 `_Nullable` 转换为 `_Nonnull`?

objective-c - 使用多级指针类型处理 _Nonnull 或 Nullable

ios - 奇怪的 CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION 警告

ios - 如何为 UITextView Swift 添加下划线/粗体/斜体功能