Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MacRuby & RubyMotion - Madridrb May 2012

MacRuby & RubyMotion - Madridrb May 2012

Mark Villacampa

May 31, 2012
Tweet

More Decks by Mark Villacampa

Other Decks in Programming

Transcript

  1. MacRuby An implementation of the Ruby language that runs on

    top of the Objective-C runtime and garbage collection (libauto) Based on Ruby 1.9 Uses LLVM and supports both ahead-of-time and just-in-time compilation Ships with OS X 10.7 Lion!!
  2. MacRuby Started by Laurent Sansonetti inside Apple Initial 0.1 release

    in March 2008 Latest stable release (0.10) March 2011 Nightlies are very stable (0.12) http://macruby.org/ https://github.com/MacRuby/MacRuby
  3. Cocoa Apple's native object-oriented API for the Mac OS X

    operating system Foundation Kit + Application Kit + Core Data frameworks Cocoa Touch: Includes gesture recognition and different UI to use in iOS
  4. How to install Install XCode (Mac App Store, Free) Install

    Command Line Tools (Preferences > Downloads) Install MacRuby Nightly If you are in OS X 10.6.8, install Bridge Support Preview 3 https://github.com/MacRuby/MacRuby/wiki/Setting-up-MacRuby
  5. Key concepts: MacRuby objects are Objective-C objects >> "Hello Madridrb!".class.ancestors

    => [String, NSMutableString, NSString, Comparable, NSObject, Kernel] Can use Ruby & Cocoa methods >> "Hello Madridrb!".upcase <- Ruby => "HELLO MADRIDRB!" >> "Hello Madridrb!".uppercaseString <- Cocoa => "HELLO MADRIDRB!"
  6. Key concepts: New method syntax: named parameters Cocoa classes need

    to be allocated and initialized >> NSString.alloc.initWithString(“Hello Madridrb!”) => "Hello Madridrb!" >> NSDictionary.alloc.initWithObjects(["foo"], forKeys: ["bar"]) => {"foo"=>"bar"}
  7. Objective-C: Ruby: a = {"foo" => ["bar", "baz"], "oof" =>

    2} NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:[NSArray arrayWithObjects:@"bar", @"baz"] forKey:@"foo"]; [dict setObject:[NSNumber numberWithInt:2] forKey:@"oof"];
  8. Objective-C: Ruby: a = {"foo" => ["bar", "baz"], "oof" =>

    2} NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:[NSArray arrayWithObjects:@"bar", @"baz"] forKey:@"foo"]; [dict setObject:[NSNumber numberWithInt:2] forKey:@"oof"];
  9. RubyMotion Built on top of MacRuby Uses a new LLVM-based

    static compiler that generates optimized machine code Memory model similar to Objective-C ARC Based on Rake http://www.rubymotion.com/
  10. RubyMotion Commercial product. Educational licenses available at discounted price. Laurent

    Sansonetti left Apple to work on it. Released May 3rd, 2012 Fast growing community!
  11. HelloMadridrb app app_delegate.rb resources spec main_spec.rb .gitignore Rakefile $ motion

    create HelloMadridrb .rb files Main delegate Images, Sounds, .xib files Tests Configuration file
  12. Holding and clicking in a UI element assigns that element

    to the self variable in the console
  13. CocoaPods is like RubyGems but for Ojective-C projects. $ sudo

    gem install cocoapods $ pod setup $ sudo gem install motion-cocoapods Choose a pod: https://github.com/CocoaPods/Specs Edit Rakefile: require 'motion-cocoapods' Motion::Project::App.setup do |app| # ... app.pods do dependency 'JSONKit' end end
  14. TestFlight helps you distribute development builds of your app to

    your betatesters. $ sudo gem install motion-testflight Download TestFlight’s SDK and put it in the “vendor” directory inside your app. require 'motion-testflight' Motion::Project::App.setup do |app| # ... app.testflight.sdk = 'vendor/TestFlight' app.testflight.api_token = '<API token>' app.testflight.team_token = '<team token>' end http://testflightapp.com/sdk/download Edit Rakefile: $ rake testflight notes='First release!' Run: