February 21, 2018 · Ralf Ebert » iOS Developer Blog »

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

Usage

generate_storyboard_constants [storyboard_file] > [constants_file]
Btn read 3c0e607615 iOS Developer Blog
Btn subscribe 930758687e Subscribe: Email · Twitter
Btn training bbbdf557d2 Next iOS training: 25. Februar - 01. März 2019, Stuttgart
Btn about 5378472193 About me · Contact