Swiftpack.co - endocrimes/AssetGen as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by endocrimes.
endocrimes/AssetGen 0.1.0
A small Swift command line tool for generating Swift code for Asset Catalog resources
⭐️ 4
🕓 4 years ago
.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: 4
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Initial Release
8 years ago

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