macruby & rubymotion - madridrb may 2012

Post on 07-May-2015

1.614 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

MacRuby & RubyMotionProgramming OS X and iOS apps with Ruby

HiI’m @MarkVillacampa

BlameHim

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!!

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

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

How to installInstall 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

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!"

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"}

1. The syntax

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

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

2. XCode

Interface Builder

3. REPL Console( Read Eva l P r i n t Loop )

4. Gems

Any gem that works with Ruby 1.9 should work with MacRuby

5. Behaviour-Driven Development

A small RSpec clone, with NSRunLoop powers.

https://github.com/alloy/MacBacon

MacBacon

6. Mac App Store

http://briquetteapp.com/

http://shop.oreilly.com/product/0636920000723.do http://manning.com/lim/

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/

RubyMotion

Commercial product. Educational licenses available at discounted price.

Laurent Sansonetti left Apple to work on it.

Released May 3rd, 2012

Fast growing community!

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

1. Interactive Console

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

2. CocoaPods

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' endend

3. TestFlight

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:

4. App Store

http://itunes.apple.com/us/app/mustachio/id525324802

https://github.com/HipByte/Mustachio

Mustachio

Demo time

Questions?

No, it doesn’t run Rails.

top related