• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Developing Cocoa Applications with macRuby
 

Developing Cocoa Applications with macRuby

on

  • 4,011 views

MacRuby presentation at MagicRuby 2011 in Orlando, Florida on February 5, 2011.

MacRuby presentation at MagicRuby 2011 in Orlando, Florida on February 5, 2011.

Statistics

Views

Total Views
4,011
Views on SlideShare
4,008
Embed Views
3

Actions

Likes
7
Downloads
36
Comments
1

3 Embeds 3

http://paper.li 1
http://a0.twimg.com 1
http://www.twylah.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • cheap mulberry
    The device incorporates an internal antenna plus optional external antenna for ultimate reception
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Developing Cocoa Applications with macRuby Developing Cocoa Applications with macRuby Presentation Transcript

    • Developing Cocoa Applications With MacRuby Brendan G. Lim @brendanlim brendan@intridea.comSaturday, February 5, 2011
    • Outline • Objective-C & Cocoa • RubyCocoa • MacRuby • Live Coding • HotCocoaSaturday, February 5, 2011
    • Objective -C • Object-oriented extensions to C • Strongly typed • Like Ruby, influenced by Smalltalk • Primarily used for Mac OS X and iOSSaturday, February 5, 2011
    • Cocoa • High-level API for Mac OS X • Set of frameworks • Includes FoundationKit, AppKit, etc. • Apps typically built using tools like XCode and Interface BuilderSaturday, February 5, 2011
    • Why make desktop apps?Saturday, February 5, 2011
    • Different ParadigmSaturday, February 5, 2011
    • Mac App Store 1. Build MacRuby application 2. Submit to App Store 4. ProfitSaturday, February 5, 2011
    • Why Ruby instead of Objective-C?Saturday, February 5, 2011
    • Apple Loves Ruby 2002 Mac OS X 10.2 Ruby 1.6.7 2005 Mac OS X 10.4 Ruby 1.8.2 2007 Mac OS X 10.5 Ruby 1.8.6 RubyCocoa, RubyGems, Rails 2009 Mac OS X 10.6 Ruby 1.8.7 RubyCocoa, RubyGems, Rails 2011 Mac OS X 10.7 Ruby 1.9.x? MacRuby? RubyCocoa, RubyGems, RailsSaturday, February 5, 2011
    • Ruby vs Objective-C object.method(param) = [object method:param];Saturday, February 5, 2011
    • Ruby vs Objective-C array = [] = NSMutableArray *array = [[NSMutableArray alloc] init];Saturday, February 5, 2011
    • Ruby vs Objective-C “ string”.strip = [@“ string” stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]Saturday, February 5, 2011
    • Ruby vs Objective-C dictionary = {“key1” => “value1”, “key2” => “value2”} = NSArray *keys = [NSArray arrayWithObjects:@”key1”,@”key2”]; NSArray *data = [NSArray arrayWithObjects:@”value1”,@”value2”]; NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];Saturday, February 5, 2011
    • +Saturday, February 5, 2011
    • RubyCocoa • Bridge between Objective-C and Ruby • Manipulate Objective-C objects using Ruby • Write Cocoa apps in Ruby • Runs on Ruby 1.8 • Ships with OSX LeopardSaturday, February 5, 2011
    • RubyCocoa vs Objective-C OSX::NSNotificationCenter.defaultCenter.addObserver_selector_name_object( self, :window_moved, "NSWindowDidMoveNotification", nil ) = [[NSNotificationCenter defaultCenter] addObserver:self, selector:@selector(windowMoved:) name:”NSWindowDidMoveNotification” object:nil];Saturday, February 5, 2011
    • So, Why Not RubyCocoa? (besides it looking gross)Saturday, February 5, 2011
    • Why Not RubyCocoa? • It’s a bridge! • Two runtimes, GCs, etc. • Object conversions • Syntax doesn’t feel like idiomatic Ruby • It’s getting replacedSaturday, February 5, 2011
    • +Saturday, February 5, 2011
    • MacRuby • Implementation of Ruby 1.9 that runs on top the Objective-C runtime • Open sourced and supported by Apple • Replacing RubyCocoa • Objects are peers with no translation layerSaturday, February 5, 2011
    • MacRuby Object NSObject String NSMutableString Number NSNumber Array NSMutableArray Hash NSMutableDictionarySaturday, February 5, 2011
    • MacRuby Objects Objective-C Classes Objective-C Methods Objective-CSaturday, February 5, 2011
    • MacRuby >> s = “magicruby” => “magicruby” >> s.class => String >> s.class.ancestors => [String,NSMutableString,NSString,Comparable,NSObject,Kernel] >> s.upcase => “MAGICRUBY” >> s.uppercaseString => “MAGICRUBY”Saturday, February 5, 2011
    • MacRuby >> NSString.new(“magicruby”) => “magicruby” >> NSString.stringWithString(“magicruby”) => “magicruby” >> NSString.alloc.initWithString(“magicruby”) => “magicruby”Saturday, February 5, 2011
    • MacRuby >> a = [] => [] >> a.class => Array >> a.class.ancestors => [Array,NSMutableArray,NSArray,Enumerable,NSObject,Kernel] >> a << “MagicRuby” => [“MagicRuby”]Saturday, February 5, 2011
    • MacRuby vs Objective-C -(id) tableView:(NSTableView *)tableView objectValueForColumn:(NSTableColumn *)column row:(int)rowIndex { .. }Saturday, February 5, 2011
    • MacRuby vs Objective-C -(id) tableView:(NSTableView *)tableView objectValueForColumn:(NSTableColumn *)column row:(int)rowIndex { .. } def tableView(tableView objectValueForColumn:column row:rowIndex) endSaturday, February 5, 2011
    • MacRuby vs Objective-C Interface Builder Outlets & Actions !Saturday, February 5, 2011
    • MacRuby vs Objective-C Interface Builder Outlets # Interface NSString *myString; @property(nonatomic,retain) IBOutlet NSString *myString; = attr_accessor :myStringSaturday, February 5, 2011
    • MacRuby vs Objective-C Interface Builder Actions # Implementation -(IBAction) myAction:(id)sender { ... } = def myAction(sender) ... endSaturday, February 5, 2011
    • MacRuby - Gem Support • sudo macgem install awesome_gem • Not all gems supported right nowSaturday, February 5, 2011
    • MacRuby - Objective-C Frameworks & Libraries • Libraries must have garbage collection support • Libraries must be turned into bundles • Frameworks can easily be includedSaturday, February 5, 2011
    • Testing MacRuby • Any Ruby testing framework instantly becomes an Objective-C testing framework • Test::Unit • RSpec • etc...Saturday, February 5, 2011
    • What tools will we be using?Saturday, February 5, 2011
    • XcodeSaturday, February 5, 2011
    • Interface BuilderSaturday, February 5, 2011
    • InstrumentsSaturday, February 5, 2011
    • Let’s build a MacRuby appSaturday, February 5, 2011
    • HotCocoa • Created by Rich Kilmer • Ruby layer that sits on top of Cocoa, etc. • Use Ruby to easily create user interfaces • Used to be included with MacRuby • Now available as a gemSaturday, February 5, 2011
    • HotCocoa win = NSWindow.alloc.initWithContentRect([10,20,300,300], styleMask: (NSTitleWindowMask | NSCloseableWindowMask | NSMiniatureizableWindowMask | NSResizeableWindowMask) = win = window :frame => [10,20,300,300]Saturday, February 5, 2011
    • HotCocoa sudo macgem install hotcocoa hotcocoa NAME_OF_APPSaturday, February 5, 2011
    • Hello World in HotCocoa require ‘hotcocoa’ class Application include HotCocoa def start application :name => "Hello" do |app| app.delegate = self window :frame => [500,500,200,100], :title => "Hello" do |win| win << label(:text => "Hello World",:layout => {:start => false}) win.will_close { exit } end end end end Application.new.startSaturday, February 5, 2011
    • Questions? MacRuby in Action http://manning.com/lim http://macruby.org http://bit.ly/macruby-getting-started http://bit.ly/macruby-examples http://bit.ly/tdd-macrubySaturday, February 5, 2011