AFNetworking/AFNetworking — Issue #222: How to run AFJSONRequestOperation syncrously
Author: hdoria
Created: 2012-02-29 02:58:51+00:00
State: open

I need to get a JSON from a webservice and return it's value. This is how am i doing:

NSURL *url = [NSURL URLWithString:kBooksJsonUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
self.jsonAppIDs = [JSON valueForKeyPath:kBooksJsonKey];
} failure:nil];

[operation start];
[operation waitUntilFinished];

NSLog(@"PRO: %@", self.jsonAppIDs);
if ((self = [super initWithProductIdentifiers:self.jsonAppIDs])) {

}
return self;

The problem is: the last lines of code (starting from NSLog) always run before self.jsonAppIDs is populated. How can i make sure that i only call my init method when self.jsonAppIDs have some data?