0
Developing Cocoa                      Applications With                       MacRuby                             Brendan ...
Outline                             •   Objective-C & Cocoa                             •   RubyCocoa                     ...
Objective -C                             •   Object-oriented extensions to C                             •   Strongly type...
Cocoa                    •   High-level API for Mac OS X                    •   Set of frameworks                    •   I...
Why make desktop apps?Saturday, February 5, 2011
Different ParadigmSaturday, February 5, 2011
Mac App Store                                  1. Build MacRuby application                                  2. Submit to ...
Why Ruby instead                              of Objective-C?Saturday, February 5, 2011
Apple Loves Ruby                             2002   Mac OS X 10.2           Ruby 1.6.7                             2005   ...
Ruby vs Objective-C                              object.method(param)                                       =             ...
Ruby vs Objective-C                              array = []                                  =               NSMutableArra...
Ruby vs Objective-C                             “ string”.strip                                    =       [@“ string” str...
Ruby vs Objective-C                     dictionary = {“key1” => “value1”, “key2” => “value2”}                             ...
+Saturday, February 5, 2011
RubyCocoa                •   Bridge between Objective-C and Ruby                •   Manipulate Objective-C objects using R...
RubyCocoa vs Objective-C   OSX::NSNotificationCenter.defaultCenter.addObserver_selector_name_object(     self,      :windo...
So, Why Not                             RubyCocoa?                             (besides it looking gross)Saturday, Februar...
Why Not RubyCocoa?                             •   It’s a bridge!                                 •   Two runtimes, GCs, e...
+Saturday, February 5, 2011
MacRuby              •   Implementation of Ruby 1.9 that runs on top                  the Objective-C runtime             ...
MacRuby                             Object     NSObject                             String     NSMutableString            ...
MacRuby                             Objects   Objective-C                             Classes   Objective-C               ...
MacRuby     >> s = “magicruby”     => “magicruby”     >> s.class     => String     >> s.class.ancestors     => [String,NSM...
MacRuby     >> NSString.new(“magicruby”)     => “magicruby”     >> NSString.stringWithString(“magicruby”)     => “magicrub...
MacRuby     >> a = []     => []     >> a.class     => Array     >> a.class.ancestors     => [Array,NSMutableArray,NSArray,...
MacRuby vs Objective-C      -(id)       tableView:(NSTableView *)tableView       objectValueForColumn:(NSTableColumn *)col...
MacRuby vs Objective-C      -(id)       tableView:(NSTableView *)tableView       objectValueForColumn:(NSTableColumn *)col...
MacRuby vs Objective-C                             Interface Builder Outlets & Actions                                    ...
MacRuby vs Objective-C                                Interface Builder Outlets         # Interface         NSString *mySt...
MacRuby vs Objective-C                              Interface Builder Actions             # Implementation             -(I...
MacRuby - Gem Support                             •   sudo macgem install awesome_gem                             •   Not ...
MacRuby - Objective-C                      Frameworks & Libraries              •   Libraries must have garbage collection ...
Testing MacRuby                 •   Any Ruby testing framework instantly becomes                     an Objective-C testin...
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.          ...
HotCocoa                win = NSWindow.alloc.initWithContentRect([10,20,300,300],                   styleMask: (NSTitleWin...
HotCocoa                             sudo macgem install hotcocoa                               hotcocoa NAME_OF_APPSaturd...
Hello World in HotCocoa    require ‘hotcocoa’    class Application      include HotCocoa      def start        application...
Questions?                                         MacRuby in Action                                         http://mannin...
Upcoming SlideShare
Loading in...5
×

Developing Cocoa Applications with macRuby

3,635

Published on

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

Published in: Technology
1 Comment
7 Likes
Statistics
Notes
  • cheap mulberry
    The device incorporates an internal antenna plus optional external antenna for ultimate reception
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
3,635
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
37
Comments
1
Likes
7
Embeds 0
No embeds

No notes for slide

Transcript of "Developing Cocoa Applications with macRuby"

  1. 1. Developing Cocoa Applications With MacRuby Brendan G. Lim @brendanlim brendan@intridea.comSaturday, February 5, 2011
  2. 2. Outline • Objective-C & Cocoa • RubyCocoa • MacRuby • Live Coding • HotCocoaSaturday, February 5, 2011
  3. 3. 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
  4. 4. 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
  5. 5. Why make desktop apps?Saturday, February 5, 2011
  6. 6. Different ParadigmSaturday, February 5, 2011
  7. 7. Mac App Store 1. Build MacRuby application 2. Submit to App Store 4. ProfitSaturday, February 5, 2011
  8. 8. Why Ruby instead of Objective-C?Saturday, February 5, 2011
  9. 9. 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
  10. 10. Ruby vs Objective-C object.method(param) = [object method:param];Saturday, February 5, 2011
  11. 11. Ruby vs Objective-C array = [] = NSMutableArray *array = [[NSMutableArray alloc] init];Saturday, February 5, 2011
  12. 12. Ruby vs Objective-C “ string”.strip = [@“ string” stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]Saturday, February 5, 2011
  13. 13. 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
  14. 14. +Saturday, February 5, 2011
  15. 15. 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
  16. 16. 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
  17. 17. So, Why Not RubyCocoa? (besides it looking gross)Saturday, February 5, 2011
  18. 18. 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
  19. 19. +Saturday, February 5, 2011
  20. 20. 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
  21. 21. MacRuby Object NSObject String NSMutableString Number NSNumber Array NSMutableArray Hash NSMutableDictionarySaturday, February 5, 2011
  22. 22. MacRuby Objects Objective-C Classes Objective-C Methods Objective-CSaturday, February 5, 2011
  23. 23. 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
  24. 24. MacRuby >> NSString.new(“magicruby”) => “magicruby” >> NSString.stringWithString(“magicruby”) => “magicruby” >> NSString.alloc.initWithString(“magicruby”) => “magicruby”Saturday, February 5, 2011
  25. 25. MacRuby >> a = [] => [] >> a.class => Array >> a.class.ancestors => [Array,NSMutableArray,NSArray,Enumerable,NSObject,Kernel] >> a << “MagicRuby” => [“MagicRuby”]Saturday, February 5, 2011
  26. 26. MacRuby vs Objective-C -(id) tableView:(NSTableView *)tableView objectValueForColumn:(NSTableColumn *)column row:(int)rowIndex { .. }Saturday, February 5, 2011
  27. 27. 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
  28. 28. MacRuby vs Objective-C Interface Builder Outlets & Actions !Saturday, February 5, 2011
  29. 29. MacRuby vs Objective-C Interface Builder Outlets # Interface NSString *myString; @property(nonatomic,retain) IBOutlet NSString *myString; = attr_accessor :myStringSaturday, February 5, 2011
  30. 30. MacRuby vs Objective-C Interface Builder Actions # Implementation -(IBAction) myAction:(id)sender { ... } = def myAction(sender) ... endSaturday, February 5, 2011
  31. 31. MacRuby - Gem Support • sudo macgem install awesome_gem • Not all gems supported right nowSaturday, February 5, 2011
  32. 32. 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
  33. 33. Testing MacRuby • Any Ruby testing framework instantly becomes an Objective-C testing framework • Test::Unit • RSpec • etc...Saturday, February 5, 2011
  34. 34. What tools will we be using?Saturday, February 5, 2011
  35. 35. XcodeSaturday, February 5, 2011
  36. 36. Interface BuilderSaturday, February 5, 2011
  37. 37. InstrumentsSaturday, February 5, 2011
  38. 38. Let’s build a MacRuby appSaturday, February 5, 2011
  39. 39. 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
  40. 40. 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
  41. 41. HotCocoa sudo macgem install hotcocoa hotcocoa NAME_OF_APPSaturday, February 5, 2011
  42. 42. 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
  43. 43. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×