Skip to content

Instantly share code, notes, and snippets.

@koke
Created April 13, 2016 09:33
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 koke/e982259b4362805d2762ad72229d0b33 to your computer and use it in GitHub Desktop.
Save koke/e982259b4362805d2762ad72229d0b33 to your computer and use it in GitHub Desktop.
func concurrent_setResizedImage(withURL url: NSURL) {
let backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
let mainQueue = dispatch_get_main_queue()
dispatch_async(backgroundQueue) { [frame] in
let resizedURL = photonize(url: url, forSize: frame.size)
let request = requestForImageUrl(resizedURL)
fetchData(request) { data in
dispatch_async(backgroundQueue, {
guard let image = imageFromResponseData(data) else {
return
}
dispatch_async(mainQueue, {
applyImage(image, to: self)
})
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment