简体   繁体   English

PFUser.currentUser()是一个数组吗?

[英]Is PFUser.currentUser() an array?

Currently trying to create an object with a pointer to the current user, however, I get an error claiming that PFUser.currentUser() is an array: 当前尝试使用指向当前用户的指针创建对象时,我收到一条错误,声称PFUser.currentUser()是一个数组:

[Error]: invalid type for key requested, expected *_User, but got array (Code: 111, Version: 1.7.4)

My code is here: 我的代码在这里:

var requests = PFObject(className: "Requests")
        requests.addObject((PFUser.currentUser()!), forKey: "requested")
        requests.save()

I just had to change the formatting a bit, but here it is. 我只需要稍微改变一下格式,但现在就是这样。

var sendRequest = PFObject(className: "Requests")
 sendRequest["requester"] = PFUser.currentUser()
 sendRequest.saveInBackgroundWithBlock{
     (success: Bool , error: NSError?) -> Void in
 }

Make sure you're logged in, else the PFUser is null.. 确保您已登录,否则PFUser为空。

The currentUser() function returns a PFUser object . currentUser()函数返回PFUser object See more here 在这里查看更多

What about using this code: 那么使用这段代码:

var request = PFObject(className: "Requests")
if let user = PFUser.currentUser() {
   request["requested"] = user
   request.save()
}

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

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