AssetGen automatically creates structs and enums for your Asset Catalogs.
It supports multiple catalogs and folders inside them.
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
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.
$ git clone https://github.com/endocrimes/AssetGen.git
$ swift build --configuration release
$ sudo cp .build/release/AssetGen /usr/local/bin/AssetGen
link |
Stars: 4 |
Last commit: 4 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics