C#: Xamarin Studio – Is it Worth a Look?

When a new programming technology comes along, it’s not always the easiest to pick up: iOS development is a case in hand. Back in July 2008, Apple opened the App Store and launched the iPhone 3G. I bought one and tried to learn to program it.

iOS developmentThere weren’t many books around and Apple’s online documentation was not the greatest, nor was Xcode, Apple’s IDE for developing software for Mac OS X and iPhone. You get a bit spoiled when you’re used to developing with Visual Studio, Microsoft’s flagship development tool. Xcode by comparison was a second rate experience.

For designing the graphical elements you had to run Interface Builder (IB), a standalone program, and had to continually switch between it and Xcode. That later changed in Xcode 4, which was a vast improvement and incorporated IB into its design.

Objective-C, the language for programming for the iPhone, was a little bit quirky even to a seasoned C/C++ developer like myself. This is a version of C with object oriented programming based on message passing capabilities that uses an intuitive, though not always the easiest to read, syntax. Learning that plus mastering the world of iPhone programming with its motley collection of View Controllers and Views was not an easy experience. Other things took priority.

Earlier this year, the team behind the open source Mono Project, the Linux equivalent of .NET, announced a renaming and re-branding of its MonoTouch, MonoDroid and MonoDevelop products to become Xamarin Studio, named after the company Xamarin.  Monodevelop was a free IDE for editing, compiling, running and debugging C# programs on Linux, Mac and Windows, all running under Mono. MonoDroid and MonoTouch were commercial versions that let you develop for Android and iPhone/iPad. Xamarin Studio is a commercial product that combines both MonoTouch and MonoDroid.

As I’ve been developing in C# for over six years, this looked promising. I had obtained a contract to convert a Windows Phone app written in VB.NET to run on iPhone, so I bought the $999 business version of Xamarin Studio. This not only lets me develop iOS and Android apps in C# on a Mac, it also has a plugin for Visual Studio 2010/2012 that lets me edit, compile and debug apps in Visual Studio with the iOS Simulator running remotely on a networked Mac.

Visual studio iOS simulator

Visual Studio iOS Simulator

There’s also a $299 Mac-only Indie version, and a free version that is a great way to try it out but only allows 32Kb apps. Although you don’t have to pay the purchase price every year, you only get upgrades for as long as you are subscribed. So that $299/$999 version will keep costing you $299/$999 every year, because Apple and Google will insist on releasing new versions of iOS and Android and you’ll need to support new features.

Xamarin Studio Programming Environment

Xamarin Studio Programming Environment

The Rise of Xamarin

Though Xamarin Studio has only been out for a few months, it’s based on the MonoTouch/MonoDroid versions that were developed over the two years prior, so it’s a well-rounded system. There are many examples with excellent source code. Documentation is definitely one of the strengths and I think all of the iOS functionality is covered there. If not, then just search for it using the phrase MonoTouch and there’s a good chance it’ll be out there. Xamarin has a great free bind tool — Objective Sharpie — that automates the conversion of APIs to C#. If you have the Beta Xcode 5, you can use it to start writing iOS 7 compatible apps now.

Getting Started

I had a few glitches after installing Xamarin Studio on a PC and Mac, first of all getting them to talk on the same network and then successfully communicating. I found plenty of good advice in the Xamarin website forums. Both IDEs (Xamarin Studio and Visual Studio + plugin) need to be registered on the Web with Xamarin. After that, most of the setup communication is done when you first create an iPhone project in Visual Studio.

I still find every day when I open Visual Studio for the first time that it needs to talk to the Mac, and this can sometimes need a relaunch of Visual Studio. What happens is that the plugin installs a Xamarin Bonjour service but doesn’t start it. The plugin instead opens the Services MMC so that you can manually start the service. I guess it’s the easiest way to keep it upgradeable.

After a couple of weeks of use, my preferred way of working is to do all editing on the PC but run it directly from the Mac. I have the project and all the files stored on Dropbox and any changes quickly propagate to the Mac. When you build the project in the Mac Xamarin Studio, it takes 5-10 seconds before the iOS simulator loads up and you can do your run/debugging. If you do the same in Visual Studio, it takes about a minute from starting the build to be able to step through with the debugger.

Visual Studio has the better debugger and it works really well remotely debugging on the PC against your app running in the iOS simulator. If it weren’t for the much longer startup delay I’d use that all the time. You can’t avoid using the Mac. If you need to design the GUI, then you need the use the Interface Builder from Xcode. There’s no equivalent on the PC yet. Xamarin has recently shown an alpha version of a Mac GUI design tool that they are bringing out soon, tailored to C# developers.

Xamarin and the iOS Ecosystem

Xamarin doesn’t use a wrapper layer but instead compiles C# code into iOS machine code for the Arm Processor. Normally C# programs on Windows, Mac and Linux are compiled into iL (Intermediate Language, similar in concept to Java bytecode). This is then loaded by the virtual machine (CLR on Windows, JVM for Java) and converted into native machine code just in time (aka JIT). That’s not allowed on iOS, hence the AOT (Ahead of Time) compilation.

Apart from a 3.5 MB overhead for the Mono runtime, there’s no real difference between Objective-C programs compiled by Xcode and those in C# compiled by Xamarin Studio; the performance should be the same. So it’s probably only a matter of time before we see iOS games appearing written in C#.

Conclusion

Xamarin is clearly onto something here as it quotes a steadily rising number of users on its website. It’s currently just over 342,000. Anyone who knows C# has the potential to write iPhone, iPad and Android apps. That’s a big deal.

On my wish list is having Xamarin able to generate asm.js code from C#, like Emscriptem does for C/C++. Then you could develop for the Web with it.

Comments

  1. BY Lelala says:

    Is it possible to share UI code and such stuff between android development and the iOS development branch or is it required to write those stuff new/from scratch for every target platform?
    And is it possible to do crosss-compilation for Android, iOS and WinPhone in XamarinStudio?

  2. BY Spencer says:

    Hi David,

    I’m planning to delve into Xamarin development. In order to setup your MAC machine, what resources did you use??? What VM software and other planning steps did you take?? Were there any gotchas??

    Appreciate the help…

  3. BY James says:

    “So that $299/$999 version will keep costing you $299/$999 every year”

    Bloody hell!! They are worse then Microsoft.

  4. Pingback: Programming for iOS With Xamarin Studio - Dice News

  5. BY Lars says:

    I have started working on this one too. It’s costly and still have many bugs. But if you have good projects that you can earn more than the cost for the IDE, you should go with it.

Post a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>