parse.com如何填充用户对象指针?

时间:2015-09-11 18:36:31

标签: parse-platform

我们如何在User对象中填充指针?在我的Parse User表中,我有以下指针数组:“toys”,指向“Toy”类型的对象。

在我的iOS客户端中:

PFUser.currentUser()?.toys将返回一个指向玩具的指针数组,而不是完整的玩具对象。 如何检索并将完整对象保存到PFUser.currentUser()?.toys ,以便下次访问PFUser.currentUser()?.toys时,我会获得完整的对象?

感谢。

更新

显示我的意思的示例代码(感谢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.
            })
        }
 })

1 个答案:

答案 0 :(得分: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!
            })
        }
 })