I am very new at iOS and objective-c development, so I am struggling with an understanding of how I do this.
First my code:
-(NSMutableArray *)messagesGetList
{
NSMutableArray *messageList = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:@"http://xxxx/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
for (NSDictionary * dataDict in JSON) {
[messageList addObject: dataDict];
}
}
failure:^(NSURLRequest *request , NSURLResponse *response , NSError *error , id JSON)
{
NSLog(@"Failed: %@", error);
}];
[operation start];
return messageList;
}
What I am having a problem with, is that I can not access the NSMutableArray *messageList inside my for (NSDictionary * dataDict in JSON) loop. I.e. nothing is added to the array while executing my loop.
How do I access the array from within my loop?
Thanks in advance for your help, fischer
NSLog(@"loop");right above youraddObjectline. Make sure you are actually in the loop at all.