Building on an earlier question:
I have an NSOperationQueue that looks like this:
NSBlockOperation *block1 = [NSBlockOperation blockOperationWithBlock:^{
[someObject someSelector];
}];
NSBlockOperation *block2= [NSBlockOperation blockOperationWithBlock:^{
[someObject anotherSelector];
}];
[block2 addDependency:block1];
[queue addOperation:block1];
[queue addOperation:block2];
Now, inside someSelector I have:
returnData = [requesterObj getDataWithURL:(NSString*)url];
where getDataWithURL contains something like:
NSURL *requestUrl = [NSURL URLWithString:strUrl];
NSMutableURLRequest *request = [NSMutableURLRequest requestUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:timeout];
NSError *requestError;
NSURLResponse *urlResponse = nil;
NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&requestError];
Now, when I add breakpoints, it appears that the second block is being called before the NSURLConnection from the first block finishes. Presumably because the call to getDataWithURL, is itself asyncronous. What's the best way to make sure that the first block doesn't complete before that request returns. Should I try using an NSInvocation to put the data inside returnData?