Image Assets Not Being Loaded in Swift Playgrounds Xcode

Some reason the image 'Ren' is not being loaded even though it is in the project how can I resolve this issue in Xcode Playgrounds?

It looks like, for whatever reason, the image "Ren" did not end up in an asset catalog, but is instead a plain resource file. In SwiftUI, by default, Image always consults asset catalogs.

Xcode or Swift Playgrounds should have automatically created an asset catalog when you first tried to add the image "Ren" to your project (and if you can reproduce this behavior, it would be very helpful to file a report at feedbackassistant.apple.com!), but since it has not, you can either:

  • Create a new asset catalog yourself in Xcode by choosing File -> New -> File from Template… and selecting "Asset Catalog" under Resources. The default name created by Swift Playgrounds is "Assets" if you want to use that. Or…
  • Load the image file in code rather than using an asset catalog. You can get the path to the image file using something like Bundle.main.path(forResource: "Ren", ofType: "png").

The first option is going to be preferable in basically every case, so I would recommend starting with that!

Image Assets Not Being Loaded in Swift Playgrounds Xcode
 
 
Q