Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's lots of ways you can do this depending on the behavior you want.</p> <p>You can send a bunch of asynchronous requests at once, track the number of requests that have been completed, and do something once they're all done:</p> <pre><code>NSInteger outstandingRequests = [requestsArray count]; for (NSURLRequest *request in requestsArray) { [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [self doSomethingWithData:data]; outstandingRequests--; if (outstandingRequests == 0) { [self doSomethingElse]; } }]; } </code></pre> <p>You could chain the blocks together:</p> <pre><code>NSMutableArray *dataArray = [NSMutableArray array]; __block (^handler)(NSURLResponse *response, NSData *data, NSError *error); NSInteger currentRequestIndex = 0; handler = ^{ [dataArray addObject:data]; currentRequestIndex++; if (currentRequestIndex &lt; [requestsArray count]) { [NSURLConnection sendAsynchronousRequest:[requestsArray objectAtIndex:currentRequestIndex] queue:[NSOperationQueue mainQueue] completionHandler:handler]; } else { [self doSomethingElse]; } }; [NSURLConnection sendAsynchronousRequest:[requestsArray objectAtIndex:0] queue:[NSOperationQueue mainQueue] completionHandler:handler]; </code></pre> <p>Or you could do all the requests synchronously in an ansynchronous block:</p> <pre><code>dispatch_queue_t callerQueue = dispatch_get_current_queue(); dispatch_queue_t downloadQueue = dispatch_queue_create("Lots of requests", NULL); dispatch_async(downloadQueue, ^{ for (NSRURLRequest *request in requestsArray) { [dataArray addObject:[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]]; } dispatch_async(callerQueue, ^{ [self doSomethingWithDataArray:dataArray]; }); }); }); </code></pre> <p>P.S. If you use any of these you should add some error checking.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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