An eject button for Interface Builder to generate swift code
Eject is a utility to transition from Interface Builder to programatic view layout. This is done by using code generation to create a .swift
file to replace the view hierarchy managed by the .xib
file.
One common pain point with Interface Builder is that as a view becomes more dynamic and is managed more programatically, Interface Builder becomes less helpful. This tool lets developers use Interface Builder without that concern, giving them an Eject button to hit when Interace Builder starts getting in the way, and provides an easy path to transition to full programatic view layout.
Yes, I understand that this is probably a bad idea. But it might not be.
Install with homebrew:
brew install eject
Use on the command line:
eject --file /path/to/MassiveViewController.xib
Copy and paste code into .swift file, and remove the .xib:
rm /path/to/MassiveViewController.xib
Or to see what changed in a xib file by looking at the changes in generated code:
TMP=`mktemp` && git show HEAD:$XIB > $TMP && diff <(eject --file $XIB ) <(eject --file $TMP)
eject
will generate code for everything it can in the .xib
file. If there is any XML that eject
does not understand, it will print out a warning message. Open an Issue with any warnings, bugs or ideas you may have.
.xib
supportview1
, view2
variable names to avoid compile errors. Supply user labels and re-generate.The Unit Tests show how much work is done. UIKit coverage is configured by the CocoaTouchBuilder using various Builders. Some configuration is generated from Interface Builder .inspector
files.
This should still be considered an Alpha quality tool.
.xib
files