Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
In this video we will discuss some of the elements that make Xamarin work for the iOS and Android operating systems. We'll see how the Xamarin platform leverages the powerful C# programing language to build native apps.
New Terms:
- .NET -- Software framework developed by Microsoft
- BCL -- Basic class library
- JIT -- Just in time compilation
- AOT -- Ahead of time compilation
- SDK -- Software development kit
Further Reading:
Xamarin for Objective-C Developers
Xamarin for Java Developers
Getting Started: Xamarin Cross Platform
Binding iOS Native Libraries
Binding Java (Android) Native Libraries
Now that we've discussed some of
the challenges with mobile development and
0:00
how Xamarin can help,
let's look at how it works.
0:04
Each platform has its own feature set,
application framework, and
0:09
execution differences.
0:13
Xamarin has Base Class Libraries, or
0:16
BCLs which provide many features
usually found in the .NET framework.
0:18
They're implemented on the native
platform and exposed through the BCL.
0:24
For example, in the BCL there's
support for Streams, IO,
0:29
XML, Databases, and Networking.
0:32
These provided base class libraries have
the same signature as the dot net BCL.
0:38
So we can write the same code for
each platform.
0:44
There are libraries provided by Xamarin
that are included in each platform project
0:47
that provide implementation for
platform SDKs.
0:52
All these features are plugged
into Visual Studio and
0:57
include IntelliSense, tools and
compilation features.
1:00
Xamarin provides bindings to the native
libraries and SDKs for each platform.
1:06
Bindings are strongly typed and
are designed to follow C# standards.
1:12
This gives developers a single
consistent programming syntax
1:18
regardless of the target platform.
1:22
For example, Java does not
have a concept of properties.
1:25
So you use Get and
Set methods to update a class variable.
1:29
But, Xamarin wraps them in
a property to match C# standards.
1:34
Other than that,
1:38
converting Java code to C# is relatively
simple cuz they share a lot of syntax.
1:39
For Objective-C developers, there are many
differences between Objective-C and C#.
1:46
So if you're converting from Objective-C,
1:52
there's some articles in the teacher's
notes to help with the transition.
1:54
Xamarin also allows us to
create an interop between
1:58
any of our favorite Objective-C or
Java libraries.
2:02
Using a declared syntax we can
bind any pre-existing library, and
2:06
make it look like a C# class and
use it in our app.
2:11
Compilation is where all
the magic happens, so
2:16
we'll spend a few minutes
talking about how it works.
2:19
As I said earlier, Android and iOS have
fundamental execution differences.
2:22
Android uses a just in
time execution model or
2:27
JIT which means that it compiles
to an intermediate language
2:30
that is interpreted and
executed when the app launches.
2:35
iOS on the other hand uses
an ahead-of-time execution model or
2:40
AOT which means everything is compiled
directly to native assembly code and
2:44
nothing is interpreted.
2:49
All of this compilation happens through
special platform specific MS built targets
2:51
that put all the pieces together and
produce the executable artifacts.
2:57
It's important to know when compiling for
iOS you need a Mac.
3:02
Because Apple's licensing does not
permit compiling on any other platform.
3:06
Android requires your target SDKs and
3:12
tools to be on your machine,
which can be downloaded when needed.
3:15
You need to sign up for Treehouse in order to download course files.
Sign up