iPhone Development with Ruby

Published: 04 Oct 2008

I'm a Java and Ruby developer and I'm interested in starting development on an idea I have which would work great as an iPhone application. Naturally, instead of learning Objective-C I started doing some research on finding out if it's possible to use another language for iPhone development. Here are some things I found along the way to answering my question:

MacRuby seems like a good place to start. "MacRuby is a version of Ruby 1.9, ported to run directly on top of Mac OS X core technologies such as the Objective-C common runtime and garbage collector, and the CoreFoundation framework. While still a work in progress, it is the goal of MacRuby to enable the creation of full-fledged Mac OS X applications which do not sacrifice performance in order to enjoy the benefits of using Ruby". Version 0.3 has added some exciting features a core library called HotCocoa (talked more about below) and support for Interface Builder: "You can define classes, outlets and actions in a MacRuby Xcode project and they will automatically appear in Interface Builder."

Dr Nic offers a project, rbiphonetest (formally called iphoneruby), to unit test iPhone apps with Ruby. In Dr Nic's own words, "I think this project can give Ruby developers a happy place to work from as they write their Objective-C/iPhone code. You still need to wire up your UI views and controller classes manually, but if you push all the “oooh that code really needs some tests” classes away from the UI-dependent frameworks then you can hook it up to rbiphonetest and write your tests in Ruby."

Apple has a page called "iPhone OS for Cocoa Developers", which describes the differences between OS X and iPhone frameworks. Note that you will need to log in to the Apple Developers network to view the page.

HotCocoa is a layer of mappings on top of common Cocoa classes to make them simpler and to put them in line with idiomatic Ruby. The post, "HotCocoa is Pretty Damn Hot", does a nice job of explaining how HotCocoa works and gives some simple examples of how to use it. For those interested, there's an interesting debate about the merits of abstraction vs. simplicity in the comments section between the author, Why the Lucky Stiff (Shoes), and Rich Kilmer of HotCocoa.

The above post about HotCocoa led me to another project called Cappaccino. "Cappuccino is built on top of standard web technologies like JavaScript, and it implements most of the familiar APIs from GNUstep and Apple's Cocoa frameworks...Cappuccino was implemented using a new programming language called Objective-J, which is modelled after Objective-C and built entirely on top of JavaScript." This is pretty interesting for those web developers out there that may need a leg up getting started with iPhone development. On the Cappuccino blog, the post "Lights Off - Porting the iPhone app to Cappuccino", tells about an existing iPhone application was ported to Cappuccino in just a couple of hours. There's also a post about an XCode plugin that's now available so you can use XCode to develop Cappuccino apps.

In conclusion, the answer to my question about the ability of being able to write an iPhone app in Ruby seems to be "not yet". It does seem that there is plenty of interest in this area and we're starting to see new tools and frameworks pop up to help in this cause. They will no doubt make it easier to approach Mac desktop and iPhone development for people that are not familiar with Objective-C, Cocoa, and the other Apple frameworks.