https://github.com/tasanobu-zz/Misen
Script to support easily using Xcode Asset Catalog in Swift.
https://github.com/tasanobu-zz/Misen
Last synced: 6 months ago
JSON representation
Script to support easily using Xcode Asset Catalog in Swift.
- Host: GitHub
- URL: https://github.com/tasanobu-zz/Misen
- Owner: tasanobu-zz
- License: mit
- Created: 2015-06-27T12:59:47.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-09-09T07:11:24.000Z (over 6 years ago)
- Last Synced: 2024-07-30T06:03:50.628Z (10 months ago)
- Language: Swift
- Homepage:
- Size: 478 KB
- Stars: 123
- Watchers: 5
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Misen - Script to support easily using Xcode Asset Catalog in Swift. (Tools / Web View)
README
# 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**](Sample/generate.sh) of the sample project.
```swift
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.
```swift
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 8.0
- Swift 3.0# Release Notes
See [Releases](https://github.com/tasanobu/Misen/releases).# License
Misen is released under the MIT license. See LICENSE for details.