Whenever I have an image asset in my Asset catalog that has variations for devices, macCatalyst won’t find the asset. This issue does not occur on iOS or iPadOS, just macCatalyst. Once I delete all variations, the image shows up correctly. If I add any variation such as alternate images for iPad, macCatalyst or Mac, the entire image again won’t be displayed.
Is anyone having similar issues?
The code snippet is really simple:
struct MyView: View {
var body: some View {
//Image name is different than the ones on the screenshots
Image("myimage")
}
}
The following image will be displayed without issues:
Adding any variations (including Mac Catalyst Scaled or Mac variations) causes the image not to be found:
2
Answers
I found a workaround since this seems to be a bug on macCatalyst.
It seems to be a requirement to add individual scales for an asset to appear on macCatalyst at all. It still fails to use the rights asset, but at least will revert to the default asset as long as all scales have been provided. If a single scale is used, there will be no image available on macCatalyst.
I therefore added the macCatalyst image as the default asset and then added an additional iPhone and iPad asset. This will correctly detect the right asset to use in iOS, but macCatalyst will always revert to the then correct default asset.
I played around with this and experienced the same issues. I came up with two solutions:
Don’t use Mac Catalyst. Create a non-Catalyst Mac build. SwiftUI code runs on iOS and macOS. In this case, the macOS app will use the Mac variation of the image asset or the Universal variation if there is no Mac variation.
If you have some reason to use Mac Catalyst, then change the line:
to:
This will allow the image to appear in iOS and macOS (via Mac Catalyst). The macOS app will use the iPad image.