Skip to content

Instantly share code, notes, and snippets.

@ShawonAshraf
Created September 3, 2019 16:01
Show Gist options
  • Select an option

  • Save ShawonAshraf/c19ac354f71e0f3b51e3c555ea86c3f9 to your computer and use it in GitHub Desktop.

Select an option

Save ShawonAshraf/c19ac354f71e0f3b51e3c555ea86c3f9 to your computer and use it in GitHub Desktop.
func setImage(from url: String) {
guard let imageURL = URL(string: url) else { return }
// just not to cause a deadlock in UI!
DispatchQueue.global().async {
guard let imageData = try? Data(contentsOf: imageURL) else { return }
let image = UIImage(data: imageData)
DispatchQueue.main.async {
self.imageView.image = image
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment