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
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 to share