Skip to content

Instantly share code, notes, and snippets.

@aGupieWare
Created November 14, 2014 21:52
Show Gist options
  • Select an option

  • Save aGupieWare/403b7c01dbf177a3278b to your computer and use it in GitHub Desktop.

Select an option

Save aGupieWare/403b7c01dbf177a3278b to your computer and use it in GitHub Desktop.
Swift client, dispatch async . . .
// endpoint of corresponding supply item image //
let urlString : String = supplyItem.bsn_image!
dispatch_async(self.backgroundQueue, { () -> Void in
/* capture the index of the cell that is requesting this image download operation */
var err : NSError?
/* get url for image and download raw data */
if err == nil {
dispatch_sync(dispatch_get_main_queue(), { () -> Void in
/* create a UIImage object from the downloaded data */
/* get the index of one of the cells that is currently being displayed */
// compare the captured cell index to some current cell index //
// if the captured cell index is equal to some current cell index //
// then the cell that requested the image is still on the screen so //
// we present the downloaded image else we do nothing //
if /* compare indices */ {
cell.imageView.image = itemImage
cell.setNeedsLayout()
}
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment