如何覆盖或清空Parse PFRelation

时间:2014-08-19 00:18:15

标签: ios objective-c parse-platform relation

我在使用Relation更新现有Parse对象时遇到问题,我希望用新的对象列表替换现有关系。不幸的是,PFRelation中没有removeAllObjects。

    PFRelation *buddies = [invitation relationForKey:@"buddies"];

    // here i need to remove all existing objects in the relation
    // eg: [buddies removeAllObjects];

    // new invites
    for (PFProfile *buddy in self.selectedBuddies) {
        [buddies addObject:buddy];
    }

清除相关对象或创建新关系并替换当前关系的正确方法是什么?

谢谢!

1 个答案:

答案 0 :(得分:2)

我所知道的唯一方法就是这样做:

PFRelation *buddies = [invitation relationForKey:@"buddies"];

PFQuery *query = [buddies query];
NSArray *array = [query findObjects];
for(PFObject *object in array)
{
   [buddies removeObject:object];

}

我不知道您是否正在使用PFObjects或PFUser来表示"好友,"所以你可能需要修改一下代码。