user19285523
user19285523

Reputation:

How to load specific image from AppIcon with macOS SwiftUI?

I want use my png files in AppIcon to show some images, as we know there are some Images needed for app icon with sizes like 1024, 512, ..., 1 pixel and for making easy for myself I name them with their size, So I want to use the png file for size 512, then I used this code:

Image("512")

But Xcode is unable to find it, since I am working on native macOS app, I cannot use UIImage as well.

Obviously I can add the needed Image to assets and that code would be working, but the idea of this question is reusing the same file, instead duplicating the same file.

Upvotes: 1

Views: 993

Answers (1)

Otter
Otter

Reputation: 419

Unfortunately, you'll have to add them as a separate asset, as otherwise you're trying to display a non-image type asset inside of an image view.

However, Apple announced at WWDC22 this week that AppIcons will now be made up of a single image asset, and I believe at this point you'll be able to achieve what you want with just one asset.

So, I'd suggest adding another asset for now, then reassess when the latest software updates launch to the public (expected in Fall/Autumn). ☺️

Upvotes: 2

Related Questions