Created
February 20, 2017 11:12
-
-
Save KyleGoslan/cd84969ee6c247955741b4af2e6b5ee2 to your computer and use it in GitHub Desktop.
UIImage View extension to load image from web url
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
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