Created
April 19, 2017 03:27
-
-
Save adagio/306b18cdd1a7a82164e53154c16cdaa7 to your computer and use it in GitHub Desktop.
ImageCaching for CellForRow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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