Below I have some code which should return an array, the response from the server happens in a block:
- (NSMutableArray *)getArray
{
NSMutableDictionary* params =[NSMutableDictionary dictionaryWithObjectsAndKeys:
@"pending", @"command",
@"2" , @"userID",
nil];
[[API sharedInstance] commandWithParams:params
onCompletion:^(NSDictionary *json) {
//result returned
if ([json objectForKey:@"error"]==nil) {
NSMutableArray *res = [[NSMutableArray alloc] init];
[res addObject:@"1234"];
RETURN HERE
} else {
//error
[UIAlertView title:@"Error" withMessage:[json objectForKey:@"error"]];
}
}];
}
After parsing the data and creating an array I want to return the array I have created for the getArray method call. So far, after hours of trying I have not had any luck, even with trying some suggestions from previous questions on stackoverflow. Any help would be appreciated.
I’d create a method in somewhere in the class let’s say
- (void)arrayFetched:(NSArray *)fetchedArray.Then you modify your code like this:
and then do want you want with the array in the
arrayFetched:method.