GithubHelp home page GithubHelp logo

adamnemecek / eject Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rightpoint/eject

0.0 2.0 0.0 266 KB

An eject button for Interface Builder to generate swift code

License: MIT License

Swift 99.73% Objective-C 0.27%

eject's Introduction

Eject

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.

Why?

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.

But But

Yes, I understand that this is probably a bad idea. But it might not be.

Usage

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.

Features

  • UIKit .xib support
  • Constraints (using Anchorage)
  • Outlet and OutletCollection support
  • Good variable names
    • Use the user entered "user label" if present
    • Snake case of the className with the namespace removed
    • Constraint variable names are long, but descriptive, (labelBottomEqualToButtonTop)
  • Code that compiles out of the box is a non-goal
    • Will not generate view1, view2 variable names to avoid compile errors. Supply user labels and re-generate.

Does it work?

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.

Todo

  • Enhance code generation approaches
  • AppKit support
  • Storyboard support?
  • Use default values to remove un-needed code
  • Better error reporting of un-interpreted flags
  • Explore generating code as a method of diffing .xib files

eject's People

Contributors

edwardloveall avatar jdhealy avatar kingofbrian avatar squaredtiki avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.