MonoTouch: Native iPhone Apps In C#

By
On September 15, 2009

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.

0 responses to “MonoTouch: Native iPhone Apps In C#”

  1. Paul says:

    FYI, the Unity game engine for iPhone has been running with Mono for well over a year. You can also write non-dynamic typed ECMA script!

  2. pTracker says:

    At first blush, this seems like an awesome idea, especially if you have a .Net background. Then you find out the cost is $999 – fairly steep for independent developers. My used iMac cost less than that. Plus, you still need a mac and Xcode to do the final app build and bundling for App store submission.

    Anyway, after further thought, it seems this is an ideal tool for enterprise IT shops with in-house .Net teams, that want to distribute iPhone apps for internal corporate use. In this scenario, the cost of MonoTouch is easily recouped by not having to retrain existing developers, or hire new ones.

    I am looking forward to reading about your experience with MonoTouch though. But even if it works well, I doubt that I, as an independent, would give up my hard-won Objective-C skills (such as they are) just to be able to nestle back into my familiar Visual Studio, C# “home”.

    Still, it’s pretty impressive, what they’ve done. Looking forward to learning more about it.

  3. elai says:

    Mono touch starts at $400 for the indie types, not $399

  4. Miguel de Icaza says:

    The cost is 399 for professionals/individuals.

    It is only 999 for companies that want to buy licenses that they can transfer to other developers.