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

Introduction to RubyMotion - The Cool Way to Wr...

Introduction to RubyMotion - The Cool Way to Write iOS Apps

Simple intro to RubyMotion
Live slides - http://gantman.github.io/RubyMotion-Intro/
Code for and from the talk - https://github.com/GantMan/RubyMotion-Intro

Avatar for Gant Laborde

Gant Laborde

October 10, 2013
Tweet

Other Decks in Technology

Transcript

  1. Author of Numerous RubyMotion projects and Pull Requests Author of

    the book RubyMotion App Development by Packt Publishing.
  2. RubyMotion - Wat? /ˈro ͞ ob ē -m ō SHən/

    noun trademark 1. A proprietary toolchain, created by HipByte SPRL, for developing native iOS and OS X applications on Apple devices and computers by statically compiling the Ruby programming language. OR Apps the Ruby Way
  3. Quick Example Objective-C button tap [button addTarget:self action:@selector(buttonTapped:) forControlEvents: UIControlEventTouchUpInside];

    // Elsewhere - (void)buttonTapped:(id)sender { self.view.backgroundColor = [UIColor redColor]; } RubyMotion button tap button.addTarget(self, action:'button_tapped', forControlEvents:UIControlEventTouchUpInside) # Elsewhere def button_tapped self.view.backgroundColor = UIColor.redColor end
  4. Better Example Objective-C button tap [button addTarget:self action:@selector(buttonTapped:) forControlEvents: UIControlEventTouchUpInside];

    // Elsewhere - (void)buttonTapped:(id)sender { self.view.backgroundColor = [UIColor redColor]; } RubyMotion button tap (with sugarcube gem) button.on(:touch) do self.view.backgroundColor = :red.uicolor end
  5. What's So Great About RubyMotion? In my opinion Gems and

    Community Editor Independence Testing! Readability Natively Compiled The REPL
  6. RubyMotion Analogy RubyMotion is to Objective-C As Coffeescript is to

    Javascript ... plus gems are kind of like jQuery plugins ... plus MacBacon has spec tests like Jasmine would ... plus the REPL lets you live-modify like developer tools ... plus it compiles and obfuscates your final codebase ... OK, this analogy got out of control
  7. Hello World $ motion create test Tests will fail class

    AppDelegate def application(application, didFinishLaunchingWithOptions:launchOptions) @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) @window.rootViewController = HelloWorldController.new @window.makeKeyAndVisible true end end class HelloWorldController < UIViewController def viewDidLoad p "Hai" end end Now tests pass!
  8. Hello World - REPL main_view = UIApplication.sharedApplication.windows[0].rootViewController.view main_view.backgroundColor = UIColor.blueColor

    OR , just command click the view! # REPL input self.backgroundColor = UIColor.whiteColor @label = UILabel.new @label.text = "Hello World" @label.sizeToFit self.addSubview(@label) # get down from there! @label.center = [100, 100] OR , use sugarcube-repl's tree command.