Objective C model - How to download image inside a model class? <p>I have the following model of a box, it is meant to download images in a background thread and create an image from this downloaded image.</p> <p>The viewcontroller has a custom uicollectioncell, but its just a uiimageview; nothing too complex.</p> <p>In the <code>cellForItemAtIndexPath</code> I want to assign the cell's imageview using the model's downloaded image.</p> <p>However, its not quite working;</p> <ol> <li>The image never appears</li> <li>If I move the background image downloader to the <code>cellForItemAtIndexPath</code> and change a few items then the image loads fine.</li> </ol> <p>But what I'm wanting is to seperate the ViewContoller and the model; the model should do the heavy lifting and the viewcontroller simply handles the display.</p> <p>Code follows</p> <pre><code>// ViewController: View Did Load - (void)viewDidLoad { [super viewDidLoad]; if (!self.picturesArray) self.picturesArray = [NSMutableArray arrayWithCapacity:kNumberOfCells]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.backgroundColor = [UIColor clearColor]; for (int i=0; i&lt;kNumberOfCells; i++) { Box *box = [[Box alloc] init]; [self.picturesArray addObject:box]; box = nil; } } // ViewController : collectionView delegage - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { MyCustomCollectionViewCell *cell = (MyCustomCollectionViewCell *) [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath]; Box *box = self.picturesArray[indexPath.row]; cell.backgroundColor = box.bgColor; cell.imageView.image = box.image; return cell; } </code></pre> <p>The <code>box</code> model is as follows</p> <pre><code>// Box model with an image property - (instancetype)init { self = [super init]; if (self) { NSURL *url = [NSURL URLWithString:kUrlString]; // Block variable to be assigned in block. __block NSData *imageData; dispatch_queue_t backgroundQueue = dispatch_queue_create("imagegrabber.bgqueue", NULL); // Dispatch a background thread for download dispatch_async(backgroundQueue, ^(void) { imageData = [NSData dataWithContentsOfURL:url]; if (imageData.length &gt;0) { // self.image is a property of the box model self.image = [[UIImage alloc] initWithData:imageData]; // Update UI on main thread dispatch_async(dispatch_get_main_queue(), ^(void) { }); } }); } return self; } </code></pre> <p>My question is this:</p> <ol> <li>How do I get the box model to download the image and then in my cellAtIndexPath make the cell's imageView assign its image from that downloaded boxmodel image?</li> </ol> <p>A further unrelated question</p> <ol> <li>Isn't it best practice to seperate the model from the actual downloading of items? But if I'm not meant to put this in the view controller, and not the model where does it go and how/whem would you call it?</li> </ol> <p>Thanks for now</p>