我正在尝试根据在当前用户 PFRelation“友谊”中发布 PFObject 的用户来查询对象。我想知道您是否可以像使用 NSArray 一样使用 PFRelation 并执行类似的操作..
@"user" 是指向发布 PFObject 的 PFUser 的指针。
PFQuery *query = [PFQuery queryWithClassName:TV_TIMELINE_POSTS];
[query includeKey:@"user"];
[query whereKey:@"user" containedIn:[PFUser currentUser][@"friendship"]];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
[self.objectArray addObjectsFromArray:objects];
}];
或者,如果实现此目的的唯一方法是使用 PFRelation 中的 PFUsers 填充 NSArray,然后使用结果进行查询
PFRelation *relation = [[PFUser currentUser] relationForKey:@"friendship"];
PFQuery *relationQuery = [relation query];
[relationQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
self.followingArray = [[NSMutableArray alloc] initWithArray:objects];
}];
PFQuery *query = [PFQuery queryWithClassName:TV_TIMELINE_POSTS];
[query includeKey:@"user"];
[query whereKey:@"user" containedIn:self.followingArray];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
[self.objectArray addObjectsFromArray:objects];
[self.collectionView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
[self.refreshControl performSelectorOnMainThread:@selector(endRefreshing) withObject:nil waitUntilDone:NO];
_isLoading = NO;
}];
在此先感谢,埃文