First thing's first: I'm fairly new to iOS development.
I'm using "RestKit" in an application I'm putting together and I'm encountering an odd situation. I have a class method of which I intend to return an NSMutableArray
. Below is the method in question:
+ (NSMutableArray *)
getGames:(Player *)user
{
NSDictionary *queryParams = @{@"user_id" : [NSString stringWithFormat:@"%d", user.user_id]};
NSMutableArray *returnArray = [[NSMutableArray alloc] init];
[[RKObjectManager sharedManager] getObjectsAtPath:@"games.json"
parameters:queryParams
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
[returnArray addObjectsFromArray:mappingResult.array];
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
[returnArray addObjectsFromArray:@[error]];
}];
return returnArray;
}
In the success
block, if I iterate through every object in the returnArray
, it gives me the results I want. Same thing goes for failure.
However, if I iterate through the same returnArray
outside of the block, in the line just above the return returnArray
statement, it's empty.
Any idea why this is happening? Since returnArray
is declared in the "getGames:
method" shouldn't it be accessible outside the success or failure blocks within the method?