MacRuby to The Max
by Brendan Lim
- 8,063 views
Introduction and overview of MacRuby. Presentation given at RubyConf India 2010 in Bangalore, India.
Introduction and overview of MacRuby. Presentation given at RubyConf India 2010 in Bangalore, India.
Accessibility
Categories
Upload Details
Uploaded via SlideShare as Apple Keynote
Usage Rights
© All Rights Reserved
Statistics
- Likes
- 13
- Downloads
- 80
- Comments
- 0
- Embed Views
- Views on SlideShare
- 8,025
- Total Views
- 8,063
- Objective-C is essentially object oriented extensions to the C language
- It’s a strongly typed language and is influenced by Smalltalk like Ruby -- Objective-C also has Smalltalk-like messaging
- There’s garbage collection in Objective-C 2.0 and also there’s also 32-bit and 64-bit support
- It includes two major frameworks, Foundation and AppKit.
- AppKit contains all the objects you need to implement your graphical user interface.
- Foundation includes a base layer of classes that can be used for any type of Cocoa app.
- Cocoa apps are typically developed using Xcode and Interface builder using Objective-C.
- The most important use of Core Foundation is for passing its own primitive types to numerous GUI related C routines
- You can recognize a Core Foundation function because the naming almost always starts with CF. Some popular ones are CFRetain and CFRelease for memory management.
- Most of Core Foundation was actually open sourced by Apple as a project called CF-Lite
- Why would we want to use Ruby instead of Objective-C?
- Here you can see how we pass a parameter to a method in ruby and in Objective-C.
- Also, if you’re wondering what the square braces are, they are for binding a message to an object in Objective-C.
- Not that bad but it gets more complicated.
- It looks like a hash, but it’s not and the order for which arguments are passed in matters.
- Also it’s good to note that most arguments are identified by name and the first argument is usually included in or attached to the method name.
- Wouldn’t it be great if we could use Ruby instead of doing all of this?
- Unless you really really like typing, I don’t see how Objective-C could seem more appealing at this point.
- RubyCocoa is a MacOSX framework
- It’s a bridge between Objective-C and Ruby and it can manipulate Objective-C objects using Ruby
- It runs on Ruby 1.8 and it allows you to simply write Cocoa apps in Ruby.
- Also, it ships standard with OSX Leopard, so if you have Leopard or Snow Leopard on your Mac, you’ve got RubyCocoa.
- This example shows the setObject forKey function in Objective-C.
- On top you can see the RubyCocoa implementation, which is more ruby like but we are oddly mixing camelcase with underscores.
- If we’ve already got something that allows us to use Ruby to make Cocoa applications, then why should I use MacRuby?
- There are also two runtimes and two garbage collectors.
- Also, there’s expensive object conversions.
- For example, the first time you access the NSTableView class, RubyCocoa will retrieve all of the necessary info regarding this class and will create a Ruby class of the same name to act as a proxy on demand.
- MacRuby is set to be the replacement for RubyCocoa.
- So if you’re not too much of a fan of Objective-C then you’re going to like MacRuby.
- Project originally started by Laurent Sansonetti of Apple, who also helped out with RubyCocoa
- Unlike RubyCocoa, there’s no bridge or translation layer. That means little to no performance penalties. This also means that Ruby objects map to Objective-C objects without any extra work from you.
- Since MacRuby 0.5’s release, they’ve supported Apple’s Grand Central Dispatch Library to support multi-core processors.
- MacRuby is supposed to be Apple’s replacement for RubyCocoa.
- Also, MacRuby 0.5 now has HotCocoa support, which I’ll briefly talk about later.
- Here you can see the foundation counterparts of these Ruby classes.
- There were able to do this because of Core Foundation, which I mentioned before, which defines all of the primitive data types.
- So what I’m trying to show you here is that you use MacRuby the same way you would use traditional ruby.
- All the Ruby types are backed by Foundation equivalents. Here you can see that instead of just a regular Ruby String object being shown, we get back an NSMutableString. Ruby classes like String are now just aliases to their Foundation counterparts.
- Also, it’s because of this that we can still call the ruby string method “upcase” and call the NSMutableString method uppercaseString.
- Here you can see us creating a new string by calling NSString.new, stringWithString, and allocating and initializing with a string.
- Also you scan ee that we get back an NSMutableArray instead of just a Ruby array.
- The Array class descends from Ruby and Cocoa objects as well.
- If you’re familiar with iPhone development, this is one of the callback methods of CoreLocation.
- We can see here that the data types for each of the arguments that we need to pass in.
- It’s pretty close except that we removed the data types for each argument and it now looks more like idiomatic ruby with named arguments.
- And remember that even though it looks like a hash, you have to make sure that the ordering stays the same.
- When building graphical interfaces with our MacRuby application we need to be able to access our instance variables in Interface Builder so that we can make connections between our controller and our view.
- We can do this by using attr_reader, attr_writer, or attr_accessor in MacRuby. In Objective-C we have to do the following below in red to create an IBOutlet in the header file.
- Also, by convention it is mandatory to have one parameter for these actions, which is noted above as sender. Sender specified in the method above would be the button that is clicked.
- Without this sender parameter, Interface Builder will not register this action.
- Sadly, you can’t yet. Apple doesn’t allow interpreted code and doesn’t support garbage collection for the iPhone OS.
- Hopefully this will change but right now you’re going to have to stick with Objective-C. You could though, use tools like Appcelerator Titanium to create native apps using JavaScript.
- If you’re interested in hearing about that please come see me after this talk - I’d love to talk about it.
- XCode is an IDE and I’m not sure how many people here use it but if you’re uncomfortable with it, you can still use your favorite text editor to work on your ruby files but you’ll have to come back to XCode to compile your application and run your application.
- Xcode isn’t installed by default but it comes on that second disk you get with OSX and it’s also available for free online.
- Interface builder allows for you to build the interfaces for your cocoa or macruby applications using a graphical user interface.
- The files you work on are called NIB files which are our views.
- Instruments allows you to profile your app, check for leaks, memory usage, cpu usage, see how many objects you create, and much more.
- You get all of this when using MacRuby.
- Any Ruby testing framework that you’d normally use can be used with MacRuby.
- HotCocoa was developed by Rich Kilmer and it’s a thin Ruby layer that sits on top of Cocoa and other frameworks.
- It was designed to simplify the way you can create user interfaces without using Interface Builder.
- MacRuby 0.5 now supports HotCocoa and it’s included in MacRuby.
- Below you can see how much nicer it is to do this using HotCocoa.
- What this does is create a window 100 pixels wide and 50 pixels tall and adds a button with the title ‘Hello’. Once you click this button it will spit out ‘World!’ to your console.
- The current release is only at version 0.5 so there’s so much more that will surprise us before 1.0 is released.
- Also, with Apple’s backing, soon everybody could be using Ruby to develop their Cocoa Desktop apps -- also possibly even for the iPhone and the iPad.
- Switched from YARV to LLVM due to YARV’s lack of machine code compilation and the global interpreter lock, which prevented true concurrency.
- MacRuby supports Just In Time and Ahead of Time compilation
- AOT compilation makes MacRuby a true Ruby compiler