Hands on with MonoTouch - C# for the Apple iPhone and iPad

When an editor asked me for a screenshot of MonoTouch, which lets you use an open-source implementation of Microsoft's .NET Framework to target Apple's iPhone and iPad, I obtained it the best way I know, which is by installing it and trying it out.

It is something I have been meaning to try for a while. There is high demand for apps on Apple's iOS, and both the iPhone and the iPad are finding their way into businesses. As all those app requests arrive on developer desks, what is the best way to meet them? They cannot be ignored for ever.

I do not doubt the implication of Steve Jobs' essay, Thoughts on Flash, that, other things being equal, the best way to develop for iOS is with Objective C. Other things are never equal though; and for developers with a ton of existing .NET Framework applications along with skills in C# the possibility of creating iOS apps in a familiar language and framework is compelling. There may even be some code that could be ported.

Monotouch is a commercial product, though you can get started for free, with the main limitation being that you can only deploy to the iPhone emulator.

Installation is not difficult, though there are a couple of big dependencies: Apple's iPhone SDK, and the full desktop version of Mono for OSX. You probably also want MonoDevelop OS X, the Mono IDE. Oh yes, and a Mac of course. Then I got started. The New Solution dialog presents a choice of several iOS project types: monotouch-1.png

I picked a Windows-based project. MonoDevelop created the project, and I could even compile and run it in the emulator, though it displayed nothing but a beautiful white space.

So far, so familiar for a Windows developer, especially as MonoDevelop feels like a cut-down Visual Studio; but double-click MainWindow.xib in the solution and you are in the alien land of Apple's Interface Builder. Still, thanks to the MonoTouch Hello World tutorial, I soon added some visual elements to the window. Then I selected the AppDelegate class, and added outlets so I could reference them from C# code. You connect outlets to visual elements by drawing a connecting line between them.

My goal was to create a to-do list app, so I added a UITableView for the list, a text input field for new items, and a button for adding them. Removing items can wait for version 2.0. Here is how it looked:

monotouch-id.png

I saved, and returned to MonoDevelop. As promised, I could now reference the outlets in code. I drew shamelessly on this example of how to code UITableViews in MonoTouch, added a few lines of my own, and soon had a working to-do list app running in the emulator.

monotuch-emulator.png

Admittedly it is not likely to quality for the App Store just yet; but even so I was impressed with how quickly you can assemble something like this. 

I was also impressed with MonoDevelop.The code completion and error reporting was excellent.

monotouch-error.png

From the user's perspective, a MonoTouch app behaves like any other iOS app. The main snag is that the Mono runtime library has to be packaged with every app, bloating the size to 5MB or more. In the context of the 16GB or more in an iPhone or iPad, that is not too bad. Note this comment in the discussion on the subject on StackOverflow:

I have 21 apps now on the App Store in MonoTouch. All going fine, great comments from users and lots of sales

In the end, that is what counts. If you are a C# developer with a need for some iPhone or iPad apps, MonoTouch is worth checking out.

0 TrackBacks

Listed below are links to blogs that reference this entry: Hands on with MonoTouch - C# for the Apple iPhone and iPad.

TrackBack URL for this entry: http://www.itjoblog.co.uk/blogadmin/mt-tb.cgi/177

1 Comments

ChrisNTR said:

Nice write up!

It's worth noting a few things;

The iOS SDK provides a iPhone Simulator and not an emulator, this means it is running X86 code and not ARM code like it would on a device. The simulator also allows JITing which is disabled on the device.

The smallest size of a MonoTouch app on the app store is around 4.2MB, although the compressed .app file that you send over to Apple comes in around 1MB, the encryption that Apple puts on bulks up the file size (as has been previously noted from those developing Unity games - which uses Mono code too.

Hope this helps,

ChrisNTR

Leave a comment

Current Vacancies from CWJobs

(* Required field)










Preferred format