AutoAssets is a Xcode build script (written in Swift) that generates a Swift source file based on the project's assets at build time.
AutoAssets generates a source file containing enumerations of each Xcode Asset, properly name spaced in the following style:
enum IconAssets: String {
case Music
case Movies
case TVShows
func image() -> NSImage {
return NSImage(named: self.rawValue)!
}
}
Instead of accessing image assets like this:
UIImage(named:"someImage")
With the enums AutoAssets generates you can access them using proper name spacing:
IconAssets.Music.image()
For more info see my post here
By Lee Morgan. If you find this useful please let me know. I'm @leemorgan on twitter.
-
Add a Run Script to the Target’s Build Phases
-
Set the Shell to
/usr/bin/swift
-
Paste the AutoAssets.swift contents into the script block
AutoAssets generates a "AutoAssets.swift" file in the Source's directory at compile time.
Include the auto generated "AutoAssets.swift" in your project.
You can then access your Assets by using the following style:
let myImage = Assets.MyCustomImage.image()
The license is contained in the "License.txt" file.