Skip to content

storyboard2code is a command line tool for converting Storyboard XML to Swift code.

License

Notifications You must be signed in to change notification settings

watanabetoshinori/storyboard2code

Repository files navigation

storyboard2code

License: MIT

Banner

storyboard2code is a command line tool for converting Storyboard XML to Swift code.

Features

  • Convert Storyboard XML to Swift source code.
  • Supports most controls and properties.
  • Supports Autolayout and Constraints.

Conversion Examples

Original storyboard2code
Auto Layout Tutorial Original storyboard2code
Github - AutoLayoutManiacs Original storyboard2code

Getting Started

Requirements

  • Xcode 10.0+

Installation

  1. Download the zip from release page.
  2. Unzip and change the permission.
# Unzip file
unzip storyboard2code.zip

cd storyboard2code

# Change permission
chmod +x storyboard2code

Usage

Converting the file

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.

Options

Output file name

You can specify the output file name with --output option.

./storyboard2code Main.storyboard --output Converted.swift

Code generate mode

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() {
		...
	}

}

Step by step guide to replacing storyboard

  1. Convert your project Storyboard file to code.
./storyboard2code Main.storyboard --codegen extension
  1. Add storyboard2code.swift file to your project.

  2. Modify ViewController code to call loadLyouts function at viewDidLoad.

override func viewDidLoad() {
    super.viewDidLoad()

    loadLayouts()
}
  1. Modify the code to call the ViewController directly.
// let viewController = self.storyboard?.instantiateViewController(withIdentifier: "ViewController") as? ViewController

let viewController = ViewController()

FAQ

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.

Author

Watanabe Toshinori – [email protected]

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

This application makes use of the following third party libraries:

About

storyboard2code is a command line tool for converting Storyboard XML to Swift code.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages