Home

Awesome

Misen

Misen is a script to support using Xcode Asset Catalog in Swift.

Features

Misen scans sub-directories in the specified Asset Catalog and creates a UIImage extension file which has the following features.

Usage

chmod +x misen.swift
./misen.swift -path PATH/TO/XCASSETS -exportPath PATH/TO/GENERATED_FILE -enumName ENUM_NAME

e.g.

Misen generates the file below from the asset catalog with 3 image sets below.
For reference, see the script of the sample project.

<img src="images/asset-catalog.png" width="30%" height="30%">
import UIKit

// MARK: - UIImage extension
extension UIImage {
    convenience init!(assetName: ImageAsset) {
        self.init(named: assetName.rawValue)
    }
}

// MARK: - ImageAsset
enum ImageAsset: String {
    case camera = "camera"
    case contact = "contact"
    case home = "home"

    var image: UIImage {
        return UIImage(named: self.rawValue)!
    }
}
class ViewController: UIViewController {

    @IBOutlet weak var cameraImageView: UIImageView! {
        didSet {
            // Instantiate UIImage directly from ImageAsset enum
            cameraImageView.image = ImageAsset.camera.image
        }
    }

    @IBOutlet weak var contactImageView: UIImageView! {
        didSet {
            contactImageView.image = ImageAsset.contact.image
        }
    }

    @IBOutlet weak var homeImageView: UIImageView! {
        didSet {
            // Instantiate UIImage with UIImage extension
            homeImageView.image = UIImage(assetName: .home)
        }
    }
    ...
}

Requirements

Release Notes

See Releases.

License

Misen is released under the MIT license. See LICENSE for details.