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

时间:2015-06-16 14:21:51

标签: ios swift parse-platform

目前尝试使用指向当前用户的指针创建对象,但是,我收到一条错误,声称PFUser.currentUser()是一个数组:

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

我的代码在这里:

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

2 个答案:

答案 0 :(得分:1)

我只需要稍微更改格式,但现在就是。

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

答案 1 :(得分:0)

确保您已登录,否则PFUser为空..

currentUser()函数返回PFUser objectSee more here

使用此代码怎么样:

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