解析中的经典模式:设置指向PFObject的指针:

let fidoTheDog = PFObject(className: "Dog")
fidoTheDog["owner"] = PFUser.currentUser()
fidoTheDog.saveInBackground()


指针存储在fidoTheDog上,但不在另一端:

我不知道我的狗是谁。我什至不知道我是否养狗。我要遍历整个狗名单,以找出哪一只是我的。

因此,我添加了一个指向fidoTheDog的指针作为我的狗。

let fidoTheDog = PFObject(className: "Dog")
fidoTheDog["owner"] = PFUser.currentUser()
fidoTheDog.saveInBackgroundWithBlock { success, error in
    let user = PFUser.currentUser()
    user["dog"] = fidoTheDog
    user.saveInBackground()
}


但是现在我有两个要求,而且很丑。

有没有办法一次将指针存储在两端?

最佳答案

如果创建狗PFObject并将其设置为用户的dog属性,然后保存用户,则Parse应该递归保存其指向的所有PFObject。

    let fidoTheDog = PFObject(className: "Dog")
    fidoTheDog["owner"] = PFUser.currentUser()
    PFUser.currentUser()!["dog"] = fidoTheDog
    PFUser.currentUser()!.saveInBackground()

关于ios - 在两个PFObject上存储一对一指针,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33469440/

10-13 08:01