I have to make multiple http requests asynchronously (one request at a time). For looping I am doing this:
-(void) Foo1
{
[makerequest];
}
-(void) requestCompletes
{
//Do something
[self Foo1:[array objectAtIndex:i++]];
}
viewDidLoad
{
[self Foo1:[array objectAtIndex:0]];
}
But looping in the completion-handler doesn’t seems a good idea to me. Is this the correct way?
No, this is not the correct way. The iOS platform has a NSOperationQueue class, which allows you to schedule operations. By creating you’re own subclass of any of the operations (NSInvocationOperation, NSBlockOperation or the NSOperation) and using it to wrap around a NSURLRequest you can easily add and execute web request by calling