Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile / Xamarin

Introduction to Xamarin

4.50/5 (14 votes)
28 Feb 2017CPOL5 min read 13.7K  
Introduction to Xamarin

At the time of writing this post, there are two popular platforms taking over the market, a two-horse race between iOS and Android. The two mobile operating systems combined for 98.4 percent worldwide market share in the fourth calendar quarter of 2015, compared to 96.4 percent in the year-ago quarter according to research firm Gartner.

For instance, when I want to check my Facebook or twitter account, I personally prefer checking it from their official mobile app rather than navigating to the site, yes believe it or not, mobile applications are taking over the web world.

Cool, as a technology enthusiast or even as a company that would like to promote itself or a product/service in the market, we have to follow this trend, but we have to play it smart, how?

Think about it, if a company would like to build an app for the three platforms: Android, iOS and Windows phone. the company has to hire resources/teams with knowledge of three programming languages: Java for Android, Objective-C or Swift for iOS and C# and XAML for Windows phone. This approach is called Siloed approach.

screen-shot-2016-10-09-at-9-49-30-pm

Now following this approach, they will end up with the following cons:

  • No code sharing between the three platforms
  • High maintenance level, since we have three platforms, resources or programming languages
  • Expensive 💰💰

On the other hand, we cannot deny how awesome the app is going to look like, it’s because:

  • You get best of class performance wise
  • Ability to access hardware easily
  • Native user experience

Some companies are frustrated by the high cost of this approach, so they follow another approach which is a Web-based app. You can reuse the code across different platforms by writing HTML, CSS and JavaScript (could be an excellent idea if you came from a web development background).

You can consider the benefits of going with this approach to be:

  • Write code once for all
  • Saving money $$$

What are the disadvantages of this approach?

  • Performance isn’t always perfect (Remember we’re running a web app).
  • It’s not always easy to access all native features of the platform.

Two of the most popular web-based frameworks are Cordova and Ionic.

The good news! we’ve got 🎉 Xamarin 🎉 which tries to give us the best of the two approaches, code sharing with C# and you end up getting a native app.

What is Xamarin?

It's a fantastic tool that has done all the work to allow us to be able to write a mobile application in C# and run it on just about any mobile platform.

  • Native UI, native API access, and native performance
  • Anything you can do in Objective-C, Swift, or Java, you can do in C# with Xamarin.
  • Ship cutting-edge apps with same-day support for new OS releases

Meet the Xamarin Family

screen-shot-2016-10-09-at-11-14-28-pm

So what’s the difference between Xamarin.iOS, Xamarin.Android and Xamarin.Forms?

Xamarin.iOS and Xamarin.Android, as indicated by their names, are the UI toolkits for building an app with the help of each platform’s APIs and the Mono .NET Framework. If you choose to build an app using these two products, you get the benefit of customising UI for each one, but there is a trade-off is to have less code sharing.

On the other hand, if you choose to build an app with Xamarin.Forms, you will write code only once and this code gets to be translated at runtime to each platform native, the good thing about this is that you might get code sharing percentage up to 90%.

I’m Confused, Which Product Shall I Choose to Build My App?

Xamarin.Forms is best for:

  • Apps that require little platform-specific functionality
  • Apps where code sharing is more important than custom UI. Developers comfortable with XAML

Xamarin.iOS & Xamarin.Android are best for:

  • Apps with interactions that require native behaviour
  • Apps that use many platform-specific APIs
  • Apps where custom UI is more important than code sharing

Advantages of Xamarin

  1. Leverage your .NET and C# knowledge
  2. Native user interface
  3. Native performance
  4. Code sharing

Disadvantages of Xamarin (Xamarin.iOS and Xamarin.Android):

  1. Not a Shared UI platform:
    Following these two products will make you write more customised UI code for each platform but at the same time, you will get the opportunity to share 60% of the code as shown below:

    screen-shot-2016-10-11-at-9-03-32-pm

  2. Hardware requirements:
    If you would you like to run/compile your iOS app using Xamarin studio or Visual Studio, you must have a mac machine to compile it for you. You can get yourself a mac machine (like me), connect one on the same network that you’re using or you can rent a mac in the cloud such as MacinCloud services.

    You can find the option that suits you well by checking Xamarin.iOS requirement & installation.

  3. Minor learning curve:
    Sure there is a learning curve to know how you are going to deal with Xamarin.Android and Xamarin.iOS APIs, and even how you are going to build UI and so on.

Did Someone Say Anything About IDEs?

Visual Studio

xamarin2x-yuj5jk33

To get all the benefits such as Team explorer or Resharper using Visual Studio is the one for you.

Xamarin Studio

ios-designer

If you’re a mac user, you can’t install Visual Studio on your machine. That’s why Xamarin Studio comes in handy. Xamarin Studio is also available for PC users but personally, I prefer using Visual studio if am running a Windows machine.

You can find all the installation instructions by checking this link.

Update (6/1/2017) Visual Studio for Mac:

At Connect(); 16 in November, Microsoft is launching a preview of Visual Studio for Mac - I couldn’t believe that I can use Visual Studio on my mac machine without the need for Bootcamp partition on my machine.
But no, after reading this amazing blog post by Mikayla Hutchinson, I realized that Visual Studio for mac is somehow similar to Xamarin Studio but with the ability to build ASP.NET Core apps.

Note they all share the same functionalities such as the drag and drop support and build your interfaces.

Now in my series, I’m going to use Xamarin Studio since I am a mac user.

Enough talking about theoretical stuff, I like to get my hands dirty with C# code, so let’s get started and build our first Xamarin app. We will have a series of posts - each post is going to build part of the app till we end up with a good solid app.
Let’s get started 🎉

What are we going to build? (Part 0)

Image 11 Image 12

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)