I'm making a little hobby app for myself. Generalist and all, working in design tools is always a struggle for me, but I wanted a nice icon. Well, I thought I'd experiment with putting together an icon as a SwiftUI view, and see if I can export it easily. It worked out pretty nicely. Here's how it works:
Make an icon in a SwiftUI view, i.e. IconView(size: CGFloat) Bonus points: you'll be able to re-use it across your app.
Make a wrapper view that will handle exporting the icon in a PNG image.
Export the icon.
Use a service to make an AppIcon.appiconset from your icon.
An Icon in a SwiftUI View
The first part is to make an IconView I made mine resizeable so I can use it on other screens in the app like this:
Exporting a PNG of an Icon from within a SwiftUI View
You can export any View as an UIImage, and then save it. A few caveats:
If you want to later use this as an icon, you should set the size of the view that you export appropriately, i.e. in this case, we'll export an IconView(size: 1024), which will be exported as a 2048x2048 PNG image, which we will then convert into an appiconset.
The snippet is designed to run on macOS. I run it as a Mac Catalyst app preview. The snippet below saves the icon into the Pictures directory. You can save the file into any directory you have access to.
Note
In theory, you could save the UIImage data and present a share sheet to export it into anything you want. Saving into a directory from within a Mac Catalyst app is just the fastest way I've found, personally. Using Pictures is just the first thing that came to my mind and was in the list of autocompletions.
Make an appiconset with CandyIcons asset generator
There are a bunch of services and apps that take an image, and generate an app asset bundle for you, but they're not all equal. I've tried a few, and CandyIcons seems to work best. It automatically makes a mac app icon with rounded corners, and the output icon quality looks great.
Warning
CandyIcons crashes for me when I'm trying to export icons for all platforms at once. But if I only choose iOS and Mac, it works fine.