About year ago I mentioned a handy set of objective-c tools called objc-codegenutils which automatically generates code for accessing elements within asset catalogs so you don’t have to go through the error prone process of entering string identifiers.
Here’s a tool from Indragie Karunaratne inspired by objc-codegenutils that allows you to automatically generate code for accessing asset catalogs, and storyboards in Swift called swiftsrc.
This example from the readme shows code generated from an Images.xcassets asset catalog:
struct Posts {
static var Star: UIImage { return UIImage(named: "Star")! }
}
static var LaunchIcon: UIImage { return UIImage(named: "LaunchIcon")! }
struct Main {
static var SearchTabIcon: UIImage { return UIImage(named: "SearchTabIcon")! }
static var ProfileTabIcon: UIImage { return UIImage(named: "ProfileTabIcon")! }
}
}
You can find swiftsrc on Github here.
A nice time-saving tool.
Original article: A Code Generation Tool For Accessing Asset Catalog And Storyboard Elements In Swift
©2015 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.