I want to get some data from web service and it works fine bu now I want to store the returned value from a variable from a block, but the variable's value is changed only inside the block and it returns null
outside the block, how can I do it ? here is my code:
-(void)getDataFromServer:(NSString *) urlString{
__block id returnedData;
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSURLCredential *credential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone];
NSMutableURLRequest *request = [manager.requestSerializer requestWithMethod:@"GET" URLString:urlString parameters:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCredential:credential];
[operation setResponseSerializer:[AFJSONResponseSerializer alloc]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// NSLog(@"Success: %@", responseObject);
returnedData = responseObject;
NSLog(@"returned data%@" , returnedData); // here returnedData contains the value that I need to store
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", error);
} ];
[manager.operationQueue addOperation:operation];
NSLog(@"returned data%@" , returnedData); // here it returns null value !!
}