Skip to content

Instantly share code, notes, and snippets.

@crewshin
Created June 16, 2019 14:36
Show Gist options
  • Save crewshin/25845d88741f6c01f07f2bd4f3bef463 to your computer and use it in GitHub Desktop.
Save crewshin/25845d88741f6c01f07f2bd4f3bef463 to your computer and use it in GitHub Desktop.
SwiftUI web image download
import SDWebImage
// ...
func fetchWeatherImage() -> Image {
let imageFileName = weather.iconUrl ?? "01d"
let uiImageView = UIImageView()
uiImageView.sd_setImage(with: URL(string: "https://path/\(imageFileName).png"), completed: nil)
if let image = uiImageView.image {
return Image(uiImage: image)
} else {
return Image(systemName: "sun.max")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment