Created
June 16, 2019 14:36
-
-
Save crewshin/25845d88741f6c01f07f2bd4f3bef463 to your computer and use it in GitHub Desktop.
SwiftUI web image download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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