28
RubyMotion Programming OS X and iOS apps with Ruby

RubyMotion

Embed Size (px)

DESCRIPTION

Charla sobre RubyMotion por Marcos Villacampa, Betabeers Madrid 23/05/2014

Citation preview

Page 1: RubyMotion

RubyMotionProgramming OS X and iOS apps with Ruby

Page 2: RubyMotion

HiI’m @MarkVillacampa

Page 3: RubyMotion

MacRuby

Started by Laurent Sansonetti inside Apple

Initial 0.1 release in March 2008

Goal: Write OS X applications in Ruby without any performance loss

Page 4: RubyMotion

MacRubyAn implementation of the Ruby language that runs on top of the Objective-C runtime and garbage collection

Based on Ruby 1.9

Uses LLVM

Eventually "sunsetted" by Apple :(

Page 5: RubyMotion

RubyMotionCommercial product.

Write OS X and iOS applications using Ruby

Laurent Sansonetti left Apple to work on it.

Released May 3rd, 2012

Awesome community!

Page 6: RubyMotion

RubyMotionBuilt 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/

Page 7: RubyMotion

Cocoa

Apple's native object-oriented API for OS X and iOS

Includes a lot of different libraries

Very mature (originally developed at NeXTSTEP in the 80s)

Page 8: RubyMotion
Page 9: RubyMotion

Key concepts:RubyMotion objects are Objective-C objects

>> "Hello Betabeers!".class.ancestors => [String, NSMutableString, NSString, Comparable, NSObject, Kernel]

Page 10: RubyMotion

Key concepts:Can use Ruby & Cocoa methods

>> "Hello Madridrb!".upcase ← Ruby => "HELLO MADRIDRB!" >> "Hello Madridrb!".uppercaseString ← Cocoa => "HELLO MADRIDRB!"

Page 11: RubyMotion

Key concepts:New method syntax: named parameters

>> NSDictionary.alloc.initWithObjects(["foo"], forKeys: ["bar"]) => {"foo"=>"bar"}

Page 12: RubyMotion

1. The syntax

Page 13: RubyMotion

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"];

Page 14: RubyMotion

2. No Xcode

Page 15: RubyMotion
Page 16: RubyMotion

HelloMadridrb

app

app_delegate.rb

resources

spec

main_spec.rb

.gitignore

Rakefile

$ motion create MotionBetabeers

.rb filesMain delegate

Images, Sounds, .xib files

Tests

Configuration file

Page 17: RubyMotion

3. Gems

Page 18: RubyMotion

http://rubymotion-wrappers.com

Can't use CRuby gems ('require' is not allowed)

Many wrappers and libraries specifically created for Rubymotion and Cocoa:

https://github.com/rubymotion/motion-kit

E.g.: Motion-Kit

Page 19: RubyMotion

4. TDD

Page 20: RubyMotion

Bacon

http://www.rubymotion.com/developer-center/articles/testing/

Rspec syntax

Helpers to test touch UI in iOS

describe "Application" do before do @app = UIApplication.sharedApplication end ! it "has one window" do @app.windows.size.should == 1 end end

Page 21: RubyMotion

6. Interactive Console (REPL)

Page 22: RubyMotion

Holding and clicking in a UI element assigns that element to the self variable in the console

Page 23: RubyMotion

7. CocoaPods

Page 24: RubyMotion

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 'Facebook-iOS-SDK' end end

Page 25: RubyMotion

8. Production Ready

Page 26: RubyMotion

http://www.rubymotion.com/apps/

Hundreds of apps in the AppStore

Used at Cabify since 2012

Page 27: RubyMotion

http://www.rubymotion.com/developer-center/

Page 28: RubyMotion

Thankswww.markvillacampa.com

Twitter: @MarkVillacampa