Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension UIImageView {
- public func imageFromUrl(urlString: String) {
- if let url = NSURL(string: urlString) {
- let request = NSURLRequest(URL: url)
- let config = NSURLSessionConfiguration.defaultSessionConfiguration()
- let session = NSURLSession(configuration: config)
- let task = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in
- if let imageData = data as NSData? {
- self.image = UIImage(data: imageData)
- }
- });
- // do whatever you need with the task e.g. run
- task.resume()
- }
- }
- }
- extension UIImageView {
- func downloadImageFrom(link link:String, contentMode: UIViewContentMode) {
- NSURLSession.sharedSession().dataTaskWithURL( NSURL(string:link)!, completionHandler: {
- (data, response, error) -> Void in
- dispatch_async(dispatch_get_main_queue()) {
- self.contentMode = contentMode
- if let data = data { self.image = UIImage(data: data) }
- }
- }).resume()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement