我在数组中有一堆来自 PFFetch 的对象。这些对象具有指向其他对象的链接(指针数组 <-> 指针)。为了限制为我的初始提取发送的数据量,我不想在提取时使用 includeKey 下载所有链接的对象。
一段时间后,我有了这些对象的一个子集,我确实想获取这些对象的相关对象和关系。如果我再次获取它们,我会在我的应用程序中复制这些对象(并且可能不必要地通过我在我的应用程序中已有的线路发送对象)
即我希望我的原始数组中的一些对象看起来就像原始提取具有:
[query includeKey:@"relationship"];
[query includeKey@"relationship.secondRelationship"];
设置在原始键上。做这个的最好方式是什么?我想象过 PFObject 上的一些 API,例如:
+(void) fetchIfNeededInBackground:(NSArray*)objects includeKey:(NSString*)key block:...
或
- (void)includeKeyAtNextFetch:(NSString*)key
但是我找不到这样的东西。
最佳答案
您可能正在寻找著名的 containedIn 查询..
这是一个使用 containedIn 解决著名问题“匹配来自 FB 的 friend ”的示例......
+(void)findFBFriendsWhoAreOnSkywall
{
// issue a fb graph api request to get the fbFriend list...
[APP huddie];
[FBRequestConnection
startForMyFriendsWithCompletionHandler:^(
FBRequestConnection *connection, id result, NSError *error)
{
if (!error)
{
// here, the result will contain an array of the user's
// FB friends, with, the facebook-id in the "data" key
NSArray *fbfriendObjects = [result objectForKey:@"data"];
int kountFBFriends = fbfriendObjects.count;
NSLog(@"myfriends result; count: %d", kountFBFriends);
// NOW MAKE A SIMPLE ARRAY of the fbId of the friends
// NOW MAKE A SIMPLE ARRAY of the fbId of the friends
// NOW MAKE A SIMPLE ARRAY of the fbId of the friends
NSMutableArray *fbfriendIds =
[NSMutableArray arrayWithCapacity:kountFBFriends];
for (NSDictionary *onFBFriendObject in fbfriendObjects)
[fbfriendIds addObject:[onFBFriendObject objectForKey:@"id"]];
for (NSString *onef in fbfriendIds)
NSLog(@"and here they are .. %@", onef);
// query to find friends whose facebook ids are in that list:
// USE THAT SIMPLE ARRAY WITH THE MAGIC 'containedIn' call...
// amazingly easy using the ever-loved containedIn:
// amazingly easy using the ever-loved containedIn:
// amazingly easy using the ever-loved containedIn:
PFQuery *SWUSERSTOADDASFRIENDS = [PFUser query];
[SWUSERSTOADDASFRIENDS whereKey:@"fbId" containedIn:fbfriendIds];
[SWUSERSTOADDASFRIENDS findObjectsInBackgroundWithBlock:^
(NSArray *objects, NSError *error)
{
if (error) // problem getting the matching-friends list
{
[PFAnalytics .. it al went to hell.];
NSLog(@"disaster at the last step! but that's ok");
[APP.hud hide:YES];
[backTo literallyGoToMainPage];
}
else
{
// so all the people in OBJECTS, now make them in to SW friends.
[PFAnalytics trackEvent:@"FBMatchDone" ...];
NSLog(@"found this many fb matches ... %d", objects.count);
[FBMatch actuallyMakeThemFriends:objects];
[APP.hud hide:YES];
[FBMatch message .. objects.count showTheseNames:objects];
}
}];
}
else // problem getting the friend list....
{
[PFAnalytics .. problem];
[APP.hud hide:YES];
[backTo literallyGoToMainPage];
}
}];
}
希望对您有所帮助!
关于ios - 如何在现有解析对象上重新加载关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24510316/