Swiftpack.co - TerjeLon/Swifticon as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by TerjeLon.
TerjeLon/Swifticon 1.1.2
Swift package for generating app icons
⭐️ 2
🕓 3 weeks ago
.package(url: "https://github.com/TerjeLon/Swifticon.git", from: "1.1.2")

Logo of Swifticon


This package allows you to generate app icons from your SwiftUI code.
In fact, the icon for this project was generated with the package itself. Want to try out the exact code used? Well here it is:

let greyscaleGradient = AngularGradient(gradient: Gradient(colors: [.white, .black]), center: .center, startAngle: .zero, endAngle: .degrees(520))
let colorfulGradient = AngularGradient(gradient: Gradient(colors: [.red, .yellow, .orange.opacity(0.8), .pink.opacity(0.8), .purple, .red]), center: .center, startAngle: .zero, endAngle: .degrees(360))

extension View {
    func multicolorGlow(gradient: AngularGradient) -> some View {
        ZStack {
            ForEach(0..<2) { i in
                    .mask(self.blur(radius: 20))
                    .overlay(self.blur(radius: 5 - CGFloat(i * 5)))


struct Icon: PreviewProvider {
    static var previews: some View {
        ZStack(alignment: .center) {
            Group {
                            lineWidth: 150
                    .offset(x: -175, y: 0)
                    .multicolorGlow(gradient: colorfulGradient)
                            lineWidth: 150
                    .offset(x: 175, y: 0)
                    .multicolorGlow(gradient: greyscaleGradient)
            .offset(x: 0, y: -100)
            LinearGradient(colors: [.black, .black, .black, .pink, .red, .orange], startPoint: .leading, endPoint: .trailing).mask({
                    .padding(.horizontal, 100)
                    .font(.system(size: 500))
            .offset(x: 0, y: 200)

Designing your icons

Simply create a preview that uses the .swifticon modifier to get a preview layer that fits for icon designing.


struct MyIcon: PreviewProvider {
    static var previews: some View {
        VStack {
            /** Icon code here*/

Generating all app icons

In a unit test, simply call try! Swifticon.generateIconAssets(...) Example:

class generateIcons: XCTestCase {
    func testGenerate() {
        try! Swifticon.generateIconAssets(
        	fromPreviews: MyIcon._allPreviews,
        	forPlatforms: [
                .iPhoneAndiPad(assetsFolderRelativePath: "iOSProjectFolder/Assets"),
                .watchOS(assetsFolderRelativePath: "watch WatchKit App/Assets")

Advanced parameters

Swifticon.generateIconAssets supports additional parameters for tweaking output location and more.

An array of platforms you want icons generated for. Defaults to all platforms.
Supported platforms are:

  • iOS
  • iPadOS
  • MacOS
  • WatchOS

Each platform needs their relative path from your projects root folder included. Example: iOSProjectFolder/Assets. Where full path would be ~/Documents/myProject/iOSProjectFolder/Assets

Name of the .appiconset folder, without suffix. Defaults to AppIcon.
Should only be set if you have multiple icons for your application, or renamed the default folder.

Renders complete view hierarchy if true.
Only set to false if tests is not run towards a simulator or device.
Might cause unexpected results when false.

Needed for getting path to project folder, no value should be set!.
If you do change this value, make sure its the absolute path to the project your generating icons for.


tvOS is not supported, and might not be unless there is a high demand for it, or someone submits a pull request that adds support. The reasoning is that the icons differ a lot from icons on the other platforms, and they are more intricate.


Stars: 2
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Fixes a crash when Contents.json does not exists
3 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics