Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

endocrimes/AssetGen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A small Swift command line tool for generating Swift code for Asset Catalog resources

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages