TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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 String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.