Retornando NSDictionary do bloco de código assíncrono? [duplicado]
Duplicata Possível:
retornando UIImage do bloco
Oi eu estou tentando devolver dicionário de dados json twitter para que eu possa usá-lo no meu aplicativo. Como sempre está sendo chamado de um bloco assíncrono. Eu não posso salvá-lo ou devolver algum pensamento?
-(NSDictionary *)TweetFetcher
{
TWRequest *request = [[TWRequest alloc] initWithURL:
[NSURL URLWithString: @"http://search.twitter.com/search.json?
q=iOS%205&rpp=5&with_twitter_user_id=true&result_type=recent"] parameters:nil
requestMethod:TWRequestMethodGET];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse
*urlResponse,
NSError *error)
{
if ([urlResponse statusCode] == 200)
{
NSError *error;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData
options:0 error:&error];
//resultsArray return an array [of dicitionaries<tweets>];
NSArray* resultsArray = [dict objectForKey:@"results"];
for (NSDictionary* internalDict in resultsArray)
NSLog([NSString stringWithFormat:@"%@", [internalDict
objectForKey:@"from_user_name"]]);
----> return dict; // i need this dictionary of json twitter data
}
else
NSLog(@"Twitter error, HTTP response: %i", [urlResponse statusCode]);
}];
}
Thnx antecipadamente!