Giter Site home page Giter Site logo

cocoaplayground / referee Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 3.0 109 KB

Ruby script to generate Objective-C classes and macros for referring to Interface Builder resources in code.

Home Page: http://dynamit.com/stream/referee-improved-class-management-for-apple-developers/

License: MIT License

Ruby 85.75% Shell 0.56% Objective-C 13.69%

referee's Introduction

Referee

Build Status Gem Version

Referee is a script that generates Objective-C classes and macros for easily referencing your resources in code, providing IDE auto-complete and compile-time safety for your app.

The currently supported resource types are:

  • Storyboards
  • View Controllers
  • Segue Identifiers
  • Table View Cell Identifiers
  • Collection View Cell Identifiers

The inspiration for this script was provided by R.swift.

Demo

Without referee, you can either maintain your own constants file in parallel with your storyboards or write code as such:

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *someViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"Some View Controller"];
[someViewController performSegue:@"Some Segue"];

With referee, you can replace this with references to a few automatically generated classes:

UIViewController *someViewController = TSTResources.viewControllers.SomeViewController;
[someViewController performSegue:TSTResources.segues.SomeSegue];

Now, if you change an identifier in your storyboard, your code won't compile unless it matches as well, providing you with the confidence that your code and UI are in sync.

Installation

referee is distributed through RubyGems. To install it, execute the following command:

$ gem install objc-referee

As a reminder, if you are using rbenv to manage your Gems, you may additionally need to run:

$ rbenv rehash

Note that Xcode does not use your standard user $PATH, so we'll need to place referee in a standard place that we can reference in our build scripts. /usr/local/bin/ is a good place for this executable:

$ ln -s $(which referee) /usr/local/bin/referee

Or if you'd rather do the above manually, here is an example using rbenv:

$ which referee
/Users/colindrake/.rbenv/shims/referee
$ ln -s /Users/colindrake/.rbenv/shims/referee /usr/local/bin/referee

Finally, if you are using a Gemfile to manage Ruby dependencies for your app or build system, make sure to add the following:

source 'https://rubygems.org'
gem 'objc-referee'

Xcode Integration

This script was designed to be easily integrated into your Xcode project workflow.

Begin by adding a Run Script to your Build Phases. For the script portion, enter:

/usr/local/bin/referee --prefix <your class prefix>

Ensure that this Run Script runs before the Compile Sources step. Otherwise, your new changes won't get compiled!

Build the project and open your source folder. By default, at the root of that folder there should be two new files: <Prefix>Resources.h and <Prefix>Resources.m. Add these files to the Xcode project, ensuring "Copy Files" is not selected.

From now on, when you make changes in your Storyboard files, they will be reflected in these source files upon compiling.

If you need to setup different paths or configure referee further, check the --help flag for more information and documentation.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.

Todos

  • Add in Image support
  • More robust method name generation
  • NIB support
  • Localized Strings?
  • Per-category toggle flags, i.e. something to the effect of --table-cells=NO

Caveats

A word of caution: using Referee on your project can make your project's binary size balloon. This is a consequence of what Referee does for you - it creates convenience classes for you, thus increasing your symbol count. On most smaller projects, this won't matter. On large ones, however, please be cautious.

Contributing

  1. Fork it ( https://github.com/dynamit/referee/fork )
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Ensure you adhere to the style guidelines (run rubocop)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin feature/my-new-feature)
  6. Create a new Pull Request

Note: The Rubocop adherence can always be improved! Please see .rubocop_todo.yml for areas that need improvement.

License

This project is MIT licensed. Please see LICENSE.txt for details.

Sponsorship

This project is sponsored by the iOS Mobile group at Dynamit, LLC.

referee's People

Contributors

cfdrake avatar lottadot avatar

Watchers

 avatar

Forkers

lalilevi1 nobre84

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.