fuza4w
Last Updated: February 25, 2016
·
275
· supremegravity
8e97d3418e72e86212ebcdd6fd3bc9d5

More rubyesque Cocoa calls with Sugarcube

Sugarcube papers over the ridiculously verbosity of iOS's APIs so you can feel like you're writing ruby again:

"http://www.cnn.com".nsurl.open

replaces the default RubyMotion way to open a URL:

UIApplication.sharedApplication.openURL(NSURL.URLWithString("http://www.cnn.com"))

If you were slogging away in Objective-C, you'd end up writing this beauty:

NSURL *url = [ [ NSURL alloc ] initWithString: @"http://www.cnn.com" ];
[[UIApplication sharedApplication] openURL:url];

Documentation

Sugarcube includes UIKit helpers, type transforms, constants, REPL helpers, CoreGraphics, and more--there are three great sources that, together, document all of this:

The original author's overview is a great place to start.

The README on github goes deeper.

For docs on all the methods see the RubyDoc pages, e.g. UIImage on RubyDoc


Four examples

  1. Scale an image "my_image".uiimage.scale_to [37, 37].

  2. Slide a view smoothly to the left? view.slide(:left, 20).

  3. Quickly post a notification: "my notification".post_notification

  4. Put a text label into a view in one line view << ('Goodbye'.italic + ' cruel world.').underline.uilabel.

Say Thanks
Respond