Git Product home page Git Product logo

misen's Introduction

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.

  • Application-specific enum which is constructed from Asset Catalog names and UIImage object can be instantiated directly from it.
  • UIImage non-failable initializer whose argument is an enum value above.

Usage

  • Change file permissions first.
chmod +x misen.swift
  • Run the script.
./misen.swift -path PATH/TO/XCASSETS -exportPath PATH/TO/GENERATED_FILE -enumName ENUM_NAME
  • -path is a path of the asset catalog.
  • -exportPath is an output UIImage extension file path.
  • -enumName is an enum name to be generated. This is optional and ImageAsset is used as default when this parameter is not specified.

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.

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)!
    }
}
  • In your code, you can instantiate images in Asset Catalog as follows.
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

  • Xcode 7.0
  • Swift 2.0

Release Notes

See Releases.

License

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

misen's People

Contributors

janselv avatar tasanobu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.