简体   繁体   English

了解有关解析最新SDK / Swift 1.2的语法问题

[英]Understanding Syntax issues about Parse latest SDK / Swift 1.2

Why does the 2nd snippet work and the first not work? 为什么第二个代码段有效而第一个代码无效?

This code does not work : 此代码不起作用

func logIn() {
    PFUser.logInWithUsernameInBackground(tv_username.text, password:tv_password.text) {
        (user: PFUser!, error: NSError!) -> Void in
        if user != nil {
            // Yes, User Exists
            //self.loginInitialLabel.text = "User Exists"
        } else {
            // No, User Doesn't Exist
        }
    }
}

This code works : 此代码有效

func logIn() {
    PFUser.logInWithUsernameInBackground(tv_username.text, password:tv_password.text) {
        (user, error) -> Void in
        if user != nil {
            // Yes, User Exists
            //self.loginInitialLabel.text = "User Exists"
        } else {
            // No, User Doesn't Exist
        }
    }
}

Below is the error message. 下面是错误消息。 I am looking for a clear explanation of why some online docs have hte first example but only the 2nd one works. 我正在寻找关于为什么某些在线文档具有第一个示例但只有第二个有效的清晰解释。 Did Parse change their SDK without changing documentation or is this some artifact of Swift 1.2 change? Parse是否在不更改文档的情况下更改了他们的SDK,还是Swift 1.2的某些工件发生了变化? I am using XCode 6.3 and Swift 1.2. 我正在使用XCode 6.3和Swift 1.2。

在此处输入图片说明

Zoom of the error message: 放大错误消息:

在此处输入图片说明

  • In the first example, you specify the types of user and error explicitly ( PFUser! and NSError! ) respectively. 在第一个示例中,您分别明确指定usererror的类型( PFUser!NSError! )。

  • In the second example, you permit the type of user and error to be supplied implicitly. 在第二个示例中,您允许隐式提供user类型和error

Thus, the fact that the first example gives a compile error must mean that your explicit types are no longer correct. 因此,第一个示例给出了编译错误这一事实必须意味着您的显式类型不再正确。 It could be the exclamation marks; 可能是感叹号; try removing them. 尝试删除它们。

The real way to figure out what types they are, though, is to use the second example, compile it, and then to put the cursor inside user and then inside error and read off the types from Quick Help on the right side of the Xcode window, as I do here: 弄清楚它们是什么类型的真正方法是使用第二个示例,对其进行编译,然后将光标置于user内部,然后置于error内部,并从Xcode右侧的快速帮助中读取类型。窗口,就像我在这里所做的那样:

在此处输入图片说明

That little trick has solved many Swift type mysteries for me! 这个小把戏为我解决了许多Swift类型的奥秘!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM