Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to know now when multiple server call methods with nested loops have all finished
    text
    copied!<p>I have multiple methods, each with nested loops and facebook requests. There is an array of X id's and each method loops through each id, makes a request for that id then does stuff with the result data. </p> <p>I need to be notified when each method has completed... ie, when the method has finished looping through all the id's in the array, making the facebook request for each, received the results and finished its tasks with the resulting data. I can't seem to figure out how to make this happen. here are examples of the methods:</p> <pre><code>- (void)runLoopForFacebookFriendsContent1 { for (NSString *fbIdStr in self.fbIdsArr){ FBRequest *fbRequest = [FBRequest requestWithGraphPath:graphPathString parameters:nil HTTPMethod:@"GET"]; [fbRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { if (error) { //show alert } else { //Do stuff with the resulting data } }]; } } - (void)runLoopForFacebookFriendsContent2 { for (NSString *fbIdStr in self.fbIdsArr){ FBRequest *fbRequest2 = [FBRequest requestWithGraphPath:graphPathStringNumber2 parameters:nil HTTPMethod:@"GET"]; [fbRequest2 startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { if (error) { //show alert } else { for (PF_FBGraphObject *obj in [result objectForKey:@"data"]){ NSLog(@"facebook result: %@",result); NSMutableDictionary *dict = [[NSMutableDictionary alloc]init]; [dict setValue:@"type2" forKey:@"ContentType"]; [dict setValue:obj forKey:@"data"]; [self.theFacebookDataArray addObject:dict]; } } }]; } } </code></pre> <p>I call these methods in viewWillAppear. is there a way to setup some sort of completion handler to put the call for these methods inside? and then post an NSNotification when they are all done?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload