title: IOS/AFNetworking: enqueue two JSON operations and then compare the returned NSArrays
body: <p>For my app, I have to connect to two webservices that return JSON.</p>
  
  <p>I first rolled my own networking code using GCD, but seeing how AFNetworking handles things, I decided to implement it. Most things went ok, but at some point I'm retrieving two arrays filled with objects. Those two arrays are then compared using a different method. Somehow the actual enqueueing is either delayed or not working, depending on the code I'm using.</p>
  
  <p>When  using: </p>
  
  <pre><code>NSArray *operations = [NSArray arrayWithObjects:operation, operation1, nil];
          AFHTTPClient *client = [[AFHTTPClient alloc]init];
  
          [client enqueueBatchOfHTTPRequestOperations:operations progressBlock:nil completionBlock:^(NSArray *operations) {
              [self compareArrays:self];
          }
  </code></pre>
  
  <p>it just hangs.</p>
  
  <p>When using:</p>
  
  <pre><code> [operation start];
      [operation1 start];
      [operation waitUntilFinished];
      [operation1 waitUntilFinished];
  
      [self compareArrays:self];
  </code></pre>
  
  <p>at the end, it gets the arrays, but only compares after the UI has been formed.</p>
  
  <p><strong>EDIT:
  I checked Dave's answer, and it looks really streamlined. 
  Would my app benefit from using the <code>AFHTTPClient</code>, or does this method (using <code>AFJSONRequestOperation</code>) offer the same features? I recall <code>AFHTTPClient</code> handling reachability on its own now (though you need to set it). I fiddled around a bit, and got this working:</strong></p>
  
  <pre><code>NSOperationQueue *queue = [[NSOperationQueue alloc]init];
      WebServiceStore *wss = [WebServiceStore sharedWebServiceStore];
      self.userData = wss.userData;
      serviceURL = [NSString stringWithFormat: @"WEBSERVICE URL"];
      NSString* zoekFruit = [NSString stringWithFormat:
                             @"%@?customer=%@&amp;gebruiker=%@&amp;password=%@&amp;breedte=%@&amp;hoogte=%@&amp;diameter=%@",
                             serviceURL,
                             self.userData.Klant,
                             self.userData.Gebruiker,
                             self.userData.Wachtwoord,
                             breedte,
                             hoogte,
                             diameter];
  
      NSURL *url = [NSURL URLWithString:[zoekFruit stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
  
          NSURLRequest *request = [NSURLRequest requestWithURL:url];
  
          AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
              id results = [JSON valueForKey:@"data"];
  
              [results enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  
                  //Initiate the BWBand
  
                  BWBand *band = [[BWBand alloc]init];
  
                  //Set the BWBand's properties with valueforKey (or so).                    
  
                  [getBandenArray addObject:band];
              }];
  
              NSLog(@"getBandenArray: %@",getBandenArray);
  
          } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
              UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error retrieving Banden" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
              [alert show];
          }];
  
         [queue addOperation:operation];
  </code></pre>