MonoTouch: Native iPhone Apps In C#

Novell and the Mono team — the folks behind the popular OSS/alternate platform .NET and Silverlight implementations — have released MonoTouch. Using MonoTouch, programmers can write native iPhone applications using C#.

I spoke with Mono Project founder Miguel de Icaza and Joseph Hill, Mono’s product manager, about the project, the audience, the programming model and the implementation:

MonoTouch, says Hill, provides a “static compiler that turns .NET executables and libraries into native applications.” According to Icaza, this straying from the Mono norm — which relies heavily on dynamic code generation — is necessary because “the [iPhone] kernel prevents JIT compilation.”

Using C# with MonoTouch gets you garbage collection, multi-threading, and features of the 3.0 edition of the language. It’s paired with a hybrid of the .NET 2.0 and Silverlight 2.0 feature sets.

MonoTouch’s programming paradigm will feel familiar to C#/.NET developers. They’ve done the heavy lifting of creating a bridging layer that handles the translation of e.g., .NET style event handling to the CocoaTouch model. MacRuby’s HotCocoa is an analog: a thin idiomatic language layer that hides the verbosity of directly translating Objective-C methods.

In practice, this means that you can write code that looks like this:

button.touchUp += delegate {
  label.Text = "You have tapped the button";
};

A low-level programming model that let’s you direct implement the CocoaTouch APIs is available too.

One of the nifty things about MonoTouch is it’s integration with Interface Builder. You can create and use NIB files more or less as you normally would. Any outlets you create in IB will automatically be fleshed out by the SDK and available for you to use in C#.

The project supports adding MonoTouch to existing Objective-C apps. That said, of the 600 beta customers only one followed that route. This supports my hunch is that most MonoTouch developers will be .NET developers wanting to reuse their skills here.

Debugging is limited to stack traces and console write-line style logging because Apple’s debugging APIs aren’t published. That said, the stack traces include line-number granularity — sounds more usable than many of the Objective-C stack traces I’ve debugged.

MonoTouch is a paid license product. A free, try-first version should be out this week.

I’ll get my hands dirty with MonoTouch and write about the experience here.


© 2008-2011 • Mobile Orchard and the Bar-Tree Logo are service marks.