Van Du Tran
Van Du Tran

Reputation: 6892

parse.com How to populate User object pointers?

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.
            })
        }
 })

Upvotes: 1

Views: 302

Answers (1)

Chaitanya Shah
Chaitanya Shah

Reputation: 173

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!
            })
        }
 })

Upvotes: 1

Related Questions