Sometimes our image doesn’t load. I’m thinking it’s because…
- Height is unknown until
.success
- Image above or below succeeds before image in question
- Request is
cancelled
Goals
- Determine why it’s failing
- If
cancelled
fetch the image again - Otherwise display the localized error description
Steps
- Display the error description
- Reload image if it was cancelled
1 Display Error Description
ErrorView
struct ErrorView: View {
var description: String
...
Text(description)
...
2 Reload on Cancelled
PodImageView
case .failure(let error): ErrorView(description: error.localizedDescription)
We could have a button shows the error, but let’s just automatically fetch the image again instead.
case .failure(let error):
if error.localizedDescription == "cancelled" {
PodImageView(url: url)
} else {
ErrorView(description: error.localizedDescription)
}
Watch the YouTube series and checkout the github repo.