iosxcodeimageswiftuiassets

Why can't SwiftUI's Image see the AppIcon file?


I noticed a weird quirk in SwiftUI. If I try and get the app icon from the Assets folder (the icon exists) using this:

Image("AppIcon")

It doesn't work. No image displays. That being said literally every other image in the Assets folder works fine though using that same line of code, just not AppIcon.

If I use this:

Image(uiImage: (UIImage(named: "AppIcon"))! )

It works perfectly fine. The app icon shows. Is there any reason why Image can't display the AppIcon asset?


Solution

  • I have not found clear documentation from Apple, but the "AppIcon" asset seems to often be blocked from the image name space.

    The workaround is to create a separate Asset with a copy of the same file.

    (When I'm prototyping new features, I like to reference the same image in an existing target.)