21. February 2018

Generate Swift constants for Storyboard identifiers

The script generate_storyboard_constants generates controller extensions with all the IDs from your storyboard:

They are generated in a single file as an extension to the controller classes, for example:

extension ExampleViewController {
    var someCell: String { return "SomeCell" }
    var someSegue: String { return "SomeSegue" }
    static var storyboardIdentifier: String { return "ExampleViewController" } 

extension OtherViewController {
    var someCell : String { return "SomeCell" }

How to install

Download the script, have a look at it and make it executable:

curl https://gist.githubusercontent.com/ralfebert/88c3c5040307b1e99a390a085b2f2a30/raw -o /usr/local/bin/generate_storyboard_constants
cat /usr/local/bin/generate_storyboard_constants
chmod u+x /usr/local/bin/generate_storyboard_constants


generate_storyboard_constants [storyboard_file] > [constants_file]
iOS Training Schulung Workshop
Nächste iOS-Schulung:
24. – 28. Juni 2019
Frankfurt am Main
iOS Buch
iOS 12-Apps entwickeln mit Swift & Xcode 10