I've written code that gathers images from JSON requests and attempts to add them to an NSMutableArray to be used later in a table view. The problem is after adding the image objects to the array, the size of my NSMutableArray is 0. Here is the relevant code:
@implementation example{
NSMutableArray *_placeImages;
}
-(void)viewDidLoad{
...
_placeImages = [[NSMutableArray alloc] init];
}
-(void)JsonQuery {
...
// Retrieve the results of the URL.
dispatch_async(kMyQueue, ^{
[self downloadImages];
[self performSelectorOnMainThread:@selector(reloadTableData) withObject:NULL waitUntilDone:YES];
});
}
-(void)downloadImages{
...
NSData* data = [NSData dataWithContentsOfURL: url];
UIImage* image = [UIImage imageWithData:data];
[_placeImages addObject:image];
}
_placeImages = [NSMutableArray new][[NSMutableArray alloc] init]. I wonder if it has to do with accessing the array from another thread.viewDidLoadis firing beforedownloadImages?