Get Updates By E-mail 

Article Written By:
Johann Dowa

A Code Generation Tool For Accessing Asset Catalog And Storyboard Elements In Swift

  •  
  •  
  •  
  •  
  •  

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 ImagesCatalog {
    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.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments