storyboard2code is a command line tool for converting Storyboard XML to Swift code.
- Features
- Conversion Examples
- Getting Started
- Usage
- Step by step guide to replacing storyboard
- FAQ
- Author
- License
- Acknowledgments
- Convert Storyboard XML to Swift source code.
- Supports most controls and properties.
- Supports Autolayout and Constraints.
Original | storyboard2code | |
---|---|---|
Auto Layout Tutorial | ||
Github - AutoLayoutManiacs |
- Xcode 10.0+
- Download the zip from release page.
- Unzip and change the permission.
# Unzip file
unzip storyboard2code.zip
cd storyboard2code
# Change permission
chmod +x storyboard2code
To converting the file, launch the tool with Storyboard file path as argument.
./storyboard2code Main.storyboard
The storyboard2code.swift
file will be generated in the same directory as the Storyboarf file when the conversion succeeds.
You can specify the output file name with --output
option.
./storyboard2code Main.storyboard --output Converted.swift
You can specify the code generate mode (class
or extension
) with --codegen
option.
./storyboard2code Main.storyboard --codegen extension
- class (default)
class ViewController: UIViewController {
func viewDidLoad() {
super.viewDidLoad()
...
}
}
- extension
extension ViewController {
func loadLayouts() {
...
}
}
- Convert your project Storyboard file to code.
./storyboard2code Main.storyboard --codegen extension
-
Add
storyboard2code.swift
file to your project. -
Modify ViewController code to call
loadLyouts
function atviewDidLoad
.
override func viewDidLoad() {
super.viewDidLoad()
loadLayouts()
}
- Modify the code to call the ViewController directly.
// let viewController = self.storyboard?.instantiateViewController(withIdentifier: "ViewController") as? ViewController
let viewController = ViewController()
When running the tool, a
dyld: Library not loaded: @rpath/libswiftCore.dylib
error occurred.
- This tool requires Swift environment. Please install xcode before running the tool.
Watanabe Toshinori – [email protected]
This project is licensed under the MIT License. See the LICENSE file for details.
This application makes use of the following third party libraries: