UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Project 7 - FastTrack AsyncImage

Forums > macOS

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!

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.