Swiftpack.co -  endocrimes/AssetGen as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
endocrimes/AssetGen
A small Swift command line tool for generating Swift code for Asset Catalog resources
.package(url: "https://github.com/endocrimes/AssetGen.git", from: "0.1.0")

AssetGen

AssetGen automatically creates structs and enums for your Asset Catalogs.

It supports multiple catalogs and folders inside them.

Usage

Usage: $ /path/to/AssetGen [--input /path/to/project/root] [--output /path/to/Assets.swift]

You get something like this:

// Generated by AssetGen.swift
import UIKit
protocol AssetGenImageProtocol: RawRepresentable {
    var image: UIImage { get }
}

extension AssetGenImageProtocol where RawValue == String {
    var image: UIImage {
        return UIImage(named: rawValue)!
    }
}

struct ImageResources {
    enum AnotherAssetCatalog: String, AssetGenImageProtocol {
        case MuteSelected = "mute selected"
    }
    enum MyAssetCatalog: String, AssetGenImageProtocol {
        case SomeAsset = "some_asset"
        enum AFolder: String, AssetGenImageProtocol {
            case LinkIcon = "link icon"
        }
    }
}

That can then be used like this:

let myImage: UIImage = ImageResources.MyAssetCatalog.SomeAsset.image

Building

To build AssetGen, you need Swift, and it's Package Manager installed.

When you have those, it can be built with:

$ swift build

And ran from within the .build directory.

Installation

$ git clone https://github.com/endocrimes/AssetGen.git
$ swift build --configuration release
$ sudo cp .build/release/AssetGen /usr/local/bin/AssetGen

GitHub

link
Stars: 3
Last commit: 1 year ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Initial Release
5 years ago

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