The text states to use AsyncImage in the following manner:
AsyncImage(url: track.artworkURL) { phase in
switch phase {
case .success(let image):
image.resizable()
case .failure(_):
Image(systemName: "questionmark")
.symbolVariant(.circle)
.font(.largeTitle)
default:
ProgressView()
}
}
But that wasn't allowing the "questionmark" image to be drawn for me, so after searching the web, I found some documentation about AsyncImage where it may have been updated recently.
It looks like AsyncImagePhase.failure(error) doesn't get called now unless the image completely fails to load. When you're just waiting for the image to load, you need to check for the phase AsyncImagePhase.empty
I read about this from the site: "https://serialcoder.dev/text-tutorials/swiftui/asyncimage-in-swiftui/"
I just changed the code slightly to:
AsyncImage(url: track.artworkURL) { phase in
switch phase {
case .success(let image):
image.resizable()
case .failure(let error):
Text(error.localizedDescription)
case .empty:
Image(systemName: "questionmark")
.symbolVariant(.circle)
.font(.largeTitle)
default:
ProgressView()
}
}
And everything now works as expected :)
I just wanted to point this out in case anyone else runs into it - thanks for a great product Paul, I'm really enjoying the lessons, keep up the great work!