简体   繁体   English

无法从Parse.com获取currentUser PFUser对象

[英]Unable to get currentUser PFUser object from Parse.com

As you can see in the screenshot below, I have three users with usernames user1, user2 and user3 in the User table. 从下面的屏幕快照中可以看到,我在User表中有三个用户,分别具有用户名user1,user2和user3。 I am trying to use the code below to get (so that I can update later) the User object with username = "user1". 我正在尝试使用下面的代码来获取(以便以后进行更新)username =“ user1”的User对象。 I dont get anything, I just get error. 我什么也没得到,我只是得到错误。

在此处输入图片说明

When the function below is run, this is printed: 运行以下功能时,将输出:

saveUserSalaryInfo() - found NOOO-NIL user matching pfquery criteria saveUserSalaryInfo()-找到符合pfquery标准的NOOO-NIL用户

This shows that it is always getting the error. 这表明它总是得到错误。 Why? 为什么? What am I doing wrong? 我究竟做错了什么?

Code : 代码

func saveUserSalaryInfo() {

    if PFUser.currentUser() != nil {
        var query = PFQuery(className:"User")
        query.whereKey("username", equalTo: "user1")
        query.findObjectsInBackgroundWithBlock {
            (users: [AnyObject]?, error: NSError?) -> Void in
            if error != nil {

                NSLog("saveUserSalaryInfo() - found some user matching pfquery criteria")

            }

            else {
                NSLog("saveUserSalaryInfo() - found NOOO-NIL user matching pfquery criteria")
            }
        }

    } else {
        NSLog("found error - current User is not logged in")
    }

}

You are doing the test the other way around, if the error is nil that means no error happened 您正在反方向进行测试,如果错误为nil,则表示未发生任何错误

if error == nil {
    NSLog("No error")
} else {
    NSLog("Error")
}

Or to check if there is data use: 或检查是否有数据使用:

if users != nil {
    NSLog("Find Users")
} else {
    NSLog("Didn't find users")
}

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

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