I\'m storing an image from a Parse database like this:
PFFile *firstImageFile = self.product[@\"firstThumbnailFile\"];
[firstImageFile getDataInBackgroundWithBlo
I would guess (based on your comments about nil above) that your code looks a little like this:
PFFile *firstImageFile = self.product[@"firstThumbnailFile"];
[firstImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
self.firstImage = [UIImage imageWithData:imageData];
}
}];
self.galleryImages = [NSArray arrayWithObjects: self.firstImage, self.secondImage, nil];
If this is the case, move the array initialization inside the completion block like so:
PFFile *firstImageFile = self.product[@"firstThumbnailFile"];
[firstImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
self.firstImage = [UIImage imageWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^{
self.galleryImages = [NSArray arrayWithObjects: self.firstImage, self.secondImage, nil];
});
}
}];
What happens in the first (your) case is that the array initialization statement runs before the completion block, so when 'first image' is actually set it is too late as the array has already been initialized.