I would agree with the others above that generally you should stick with AFNetworking Asynchronous nature, but there are ways to cause pseudo synchronous code to run for AFNetworking requests.
Using your example the code below should work.
-(BOOL)download {
BOOL ret = TRUE;
__block BOOL complete = NO;
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
ret = [self handle:data];
complete = YES;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", error);
complete = YES;
}];
[operation start];
while(complete == NO) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
}
return ret;
}
I have found this kind of usage to be particularly useful with unit testing API's. Nesting can become quite annoying if you have to do API calls just to get to the call you want to test. This is a nifty tool to get around that.