dmytro-anokhin / url-image

AsyncImage before iOS 15. Lightweight, pure SwiftUI Image view, that displays an image downloaded from URL, with auxiliary views and local cache.
MIT License
1.11k stars 97 forks source link

Nil image url from API #73

Closed ParisJacksonNewman closed 4 years ago

ParisJacksonNewman commented 4 years ago

I am an inexperienced developer using a News API to load images into a list, however, occasionally, the json will have nil for the urlToImage and I have no idea how to solve this problem.

Here is a link to the more detailed problem. Link

dmytro-anokhin commented 4 years ago

Hey,

if your URL can be nil - use a condition. You can use ZStack, AnyView, map - there are various ways to conditionally display a view in SwiftUI - the choice is yours 😉

As for URLImage, initializer expects non-optional URL, same as standard Image expects the image name.