1

How do we populate pointers in the User object? In my Parse User table, I have the following array of pointers: "toys", that points to an object of type "Toy".

In my iOS client:

PFUser.currentUser()?.toys will return an array of pointers to toys, not full Toy objects. How do I retrieve and persists the full objects into PFUser.currentUser()?.toys so that the next time I access PFUser.currentUser()?.toys, I get full objects?

Thanks.

UPDATE:

Sample code that shows what i mean (thanks Chaitanya Shah):

let query = PFUser.query()!
query.includeKey("toys")
query.getObjectInBackgroundWithId(PFUser.currentUser()!.objectId!, block: {
    (object: PFObject?, error: NSError?) -> Void in
        if object != nil {
            if let toys = object!["toys"] as? [PFObject] {
                println(toys) // full Toy objects
                println(PFUser.currentUser()?.toys) // Toy pointers
                // the two toys above won't be the same. What I want is
                // to have PFUser.currentUser() contains fully fetched toys
                // objects so I can use it throughout my app later without
                // have to re-fetch them.
            })
        }
 })
0

1 Answer 1

1
let query = PFUser.query()!
query.includeKey("toys")
query.getObjectInBackgroundWithId(PFUser.currentUser()!.objectId!, block: {
    (object: PFObject?, error: NSError?) -> Void in
        if object != nil {
            if let toys = object!["toys"] as? [PFObject] {
                // toys!
            })
        }
 })
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, but if you access PFUser.currentUser()!.toys it's still an array of pointers, which is the essence of my question.
@VanDuTran , this answer is correct, but weak because it contains no explanation. The essential part is query.includeKey("toys"), which causes the query to also fetch the related objects referred to by the pointers in the toys array.
@danh I understand the query.includeKey("toys"). However, the PFObject?/PFUser? returned by query.getObjectInBackgroundWithId() is NOT the same as PFUser.currentUser(), so after this method call, PFUser.currentUser()!.toys is still pointers not full objects. I will add more details to my original question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.