Skip to content

Instantly share code, notes, and snippets.

@KyleGoslan
Created February 20, 2017 11:12
Show Gist options
  • Save KyleGoslan/cd84969ee6c247955741b4af2e6b5ee2 to your computer and use it in GitHub Desktop.
Save KyleGoslan/cd84969ee6c247955741b4af2e6b5ee2 to your computer and use it in GitHub Desktop.
UIImage View extension to load image from web url
extension UIImageView {
public func imageFromServerURL(urlString: String) {
URLSession.shared.dataTask(with: NSURL(string: urlString)! as URL, completionHandler: { (data, response, error) -> Void in
if error != nil { return }
DispatchQueue.main.async(execute: { () -> Void in
let image = UIImage(data: data!)
self.image = image
})
}).resume()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment