Skip to content

Instantly share code, notes, and snippets.

@adagio
Created April 19, 2017 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adagio/306b18cdd1a7a82164e53154c16cdaa7 to your computer and use it in GitHub Desktop.
Save adagio/306b18cdd1a7a82164e53154c16cdaa7 to your computer and use it in GitHub Desktop.
ImageCaching for CellForRow
let id = thought.valueForKey("id") as! String
if let cachedImage = ImageCache.sharedCache.imageForKey("image-\(id)") {
cell.picture.image = cachedImage
} else {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
let scaledImage = Helper.scaleUIImageToSize(image!, size: size)
ImageCache.sharedCache.setImage(scaledImage, forKey: "image-\(id)")
dispatch_async(dispatch_get_main_queue(), {
cell.picture.image = scaledImage
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment