Skip to content

Instantly share code, notes, and snippets.

@fisherds
Last active April 22, 2022 15:10
Show Gist options
  • Select an option

  • Save fisherds/9d6b76a2ff5bfe8ce42352b7d45ce846 to your computer and use it in GitHub Desktop.

Select an option

Save fisherds/9d6b76a2ff5bfe8ce42352b7d45ce846 to your computer and use it in GitHub Desktop.
Swift code to manual load an image view with a URL (spoiler alert we'll replace this with the Kingfisher pod)
func load(imageView: UIImageView, from url: String) {
if let imgUrl = URL(string: url) {
DispatchQueue.global().async { // Download in the background
do {
let data = try Data(contentsOf: imgUrl)
DispatchQueue.main.async { // Then update on main thread
imageView.image = UIImage(data: data)
}
} catch {
print("Error downloading image: \(error)")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment