1. Technology

iOS Development in C# with Xamarin Studio and Visual Studio

A quick overview

By

In the past I'd toyed with Objective-C ad iPhone development but I guess the combination of a new architecture and a new programming language together was too much for me. Now though with Xamarin Studio, and programming it in C#, I'm finding the architecture not that bad. I may end up coming back to Objective-C though Xamarin makes feasible any type of iOs programming including games.

This is the first of a set of tutorials on programming iOS Apps (ie both iPhone and iPad) and eventually Android Apps in C# using Xamarin Studio. So what is Xamarin Studio?

Previously known as MonoTouch Ios and MonoDroid (for Android), the Mac software is Xamarin Studio. This is an IDE that runs on Mac OS X and it's pretty good. If you've used MonoDevelop, then you'll be on familiar ground. It's not quite as good as Visual Studio in my opinion but that's a matter of taste and cost. Xamarin Studio is great for developing iOS Apps in C# and I guess Android though I haven't created any of those yet.

Xamarin Versions

Xamarin Studio comes in four versions: There's the free one that can create Apps for the App store but those are limited to 32Kb in size which is not a lot! The other three cost starting with the Indie version for $299. On that you develop on the Mac and can produce Apps of any size.

Next is the Business version at $999 and that's the one I have. As well as Xamarin Studio on the Mac it integrates with Visual Studio so you can develop iOS/Android apps as if writing .NET C#. The clever trick is that it uses your Mac to build and debug the App using the iPhone/iPad simulator while you step through code in Visual Studio.

The big version is the Enterprise edition but as I haven't got that, I won't cover it here.

In all four cases you need to own a Mac and to deploy Apps in the App store needs you to pay Apple $99 each year. You can manage to offset paying that until you need it, just develop against the iPhone simulator that comes with Xcode. You have to install Xcode but it's in the Mac Store and it's free.

Now I have been developing with the Business edition but apart from being on Windows instead of the Mac with free and Indie editions, and using the full power of Visual Studio (and Resharper) there isn't that big a difference. Part of that comes down to whether you prefer to develop Nibbed or Nibless?

Nibbed or Nibless

Xamarin integrates into Visual Studio as a plugin that gives new menu options. But it dopesn't yet come with a designer like the Xcode's Interface Builder. If you are creating all your views ( the iOS word for controls) at runtime then you can run nibless. A nib (extemnsion .xib) is an XML file that defines the controls etc in views and links events together so when you click on a control, it invokes a method.

Xamarin Studio also requires you to use Interface Builder to create nibs but at the time of writing they have a Visual designer running on the Mac in alpha state. I'm guessing in a few months that will become available and hopefully on the PC as well.

Xamarin Covers the Whole iOS API

The whole iOS API is pretty massive. Apple currently has 1705 documents in the iOS developer library covering all aspects of iOS development. Since I last looked at them, the quality has improved a lot.

Likewise the iOS API from Xamarin is pretty comprehensive, though you will find yourself referring back to the Apple docs.

Getting Started

After installing Xamarin software on your Mac, create a new Solution. The project choices include iPAD, iPhone and Universal and also with Storyboards. For iPhone you then have the choice of an Empty Project, Utility Application, Master-Detail Application, Single View application, Tabbed APplication or OpenGl Application. You have similar choices for Mac and Android development.

Given the lack of designer on Visual Studio, I've taken the nibless (Empty Project) route. It's not that difficult but nowhere as easy to get the design looking spot on. In my case, as I am mainly dealing with square buttons, it's not a worry.

Architecting iOS Forms

You are entering into a world described by Views and ViewControllers and these are most important concepts to understand. A ViewController (of which there are several types) controls how data is displayed and manages view and resource management tasks. The actual displaying is done by a View (well a UIView descendant).

The User Interface is defined by ViewControllers working together. We'll see that in action in tutorial two when I'll create a simple nibless App like this one.

In the next tutorial, we'll look in depths at ViewControllers and develop the first complete App.

  1. About.com
  2. Technology
  3. C / C++ / C#
  4. C Programming
  5. iPhone Coding Tutorials
  6. iOS Development in C# with Xamarin Studio and Visual Studio

©2014 About.com. All rights reserved.