I'm using AFNetworking
2 to GET data from server and I need to get back the responseObject
but no matter what I do i still get <null>
.
Here is the method which is sending GET request to server and in response it gets NSDictionary
which I want to use in another method...
- (void)getCurrentVersionsForTimetableWithID:(NSString *)timetableID
{
[[AFHTTPRequestOperationManager manager] GET:[NSString stringWithFormat:VERSIONS, timetableID] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
// Here I want to get responseObject
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Couldn't get current versions: %@", [error localizedDescription]);
}];
}
If I call this method everything works fine. But when I try to make it return NSDictionary
like this:
- (NSDictionary *)getCurrentVersionsForTimetableWithID:(NSString *)timetableID
{
__block NSDictionary *currentVersions;
[[AFHTTPRequestOperationManager manager] GET:[NSString stringWithFormat:VERSIONS, timetableID] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
currentVersions = responseObject;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Couldn't get current versions: %@", [error localizedDescription]);
}];
return currentVersions;
}
I get <null>
value. I know this is happening because of async but how to solve this? I've tried to pass another completion block to this method but when I call it inside another one I still cannot assign the result to the variable... Please guys, help me!