Is PFUser.currentUser () an array?

Currently, while trying to create an object with a pointer to the current user, I get an error stating that PFUser.currentUser () is an array:

[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()

      

+3


source to share


2 answers


I just had to change the formatting a bit, but this is it.



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

      

+1


source


Make sure you are logged in, otherwise PFUser is null.

The function currentUser()

returns a PFUser object

. See here for details



How about using this code:

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

      

0


source







All Articles