Skip to content

Instantly share code, notes, and snippets.

@alexsanchezdev
Last active December 12, 2019 14:33
Show Gist options
  • Save alexsanchezdev/00d68edfcd2b6188620534191ed2d309 to your computer and use it in GitHub Desktop.
Save alexsanchezdev/00d68edfcd2b6188620534191ed2d309 to your computer and use it in GitHub Desktop.
URLSession download images example | Swift 3
if let image = imageURL {
let url = URL(string: image)
URLSession.shared.dataTask(with: url!, completionHandler: { (data, response, error) in
if error != nil {
print(error!)
return
}
DispatchQueue.main.async {
imageView.image = UIImage(data: data!)
}
}).resume()
}
@alexsanchezdev
Copy link
Author

@nisha-1 maybe a late reply, but keep in mind this was a code for a custom cell. I already edit it to be useful in any case, didn't try it yet but should work.

@alexsanchezdev
Copy link
Author

@albaqawi thanks! Really appreciate the comment, will check it in new Xcode versions and make any change needed, didn't touch Xcode for a long time now hahaha

@alexsanchezdev
Copy link
Author

@asselinka default cells don't have image views in it, you can only access "title" and "subtitle" if I remember right... You have to make a custom cell with an imageView inside and then refer it in your code... Could be that the problem?

@kiritm-nimblechapps
Copy link

@guptshivu
Copy link

I am new in this.Can you please tell me how can you downloads 100 images asynchronously at a time using this?

@Aizaz-Abbasi
Copy link

how can we use this in collection view where is doesn't load all images some times repeat same image??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment