Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Compiling an iOS project


In this recipe, we will discuss how to compile a project with Xamarin.iOS.

Getting ready

Xamarin Studio provides many different options for compiling. In this recipe, we will discuss these options. We will be working with the project ButtonInput we created earlier in this chapter.

How to do it...

Perform the following steps to compile an iOS project with Xamarin.iOS:

  1. With the project loaded in Xamarin Studio, go to Project | ButtonInput Options.

  2. In the window that appears, select iOS Build from the Build section on the left pad. Select Debug as project configuration and iPhoneSimulator as a platform.

  3. In the Linker behavior field, select Link all assemblies from the combo box.

  4. In the SDK version field, select Default if it is not already selected.

  5. Now go to iOS Application on the left pad.

  6. In the Summary tab, enter Button Input in the Application Name field and 1.0 in the Version field. Select version 6.0 in the Deployment Target combo box. The iOS Application options window is shown in the following screenshot:

  7. Click on the OK button and compile the project by navigating to Build | Build All in the menu bar.

How it works...

We have set up some options for our project. Let's see what these options provide for compilation customization:

iOS build options

The first option we set up relates to the linker. The linker is a tool that was developed by the Xamarin.iOS team and is provided in the SDK. Every time a Xamarin.iOS project is compiled, the compiler does not only compile the project, it also needs all the assemblies of the Xamarin.iOS Framework so that the final app will be able to run on the device (or the simulator). This actually means that every app comes with its own compiled version of the Xamarin.iOS Framework. The final application bundle is quite large in size. This is where the linker comes in. What it does is strips down the assemblies of all the unused code so that the compiler will only compile what is needed and used by the app. This results in much smaller app bundles, a precious asset when it comes to mobile apps. The following are the linker options:

  • Don't Link: Use this option when debugging on the simulator. The linker is turned off and all the assemblies are compiled as they are. It provides faster compilation time.

  • Link SDK assemblies only: The linker only strips down the Xamarin.iOS Framework assemblies. The project assemblies remain intact. It effectively reduces the final size of the app.

  • Link all assemblies: The linker is activated on all assemblies. This reduces the size a bit more. Care needs to be taken when using this option if reflection or serialization is used in the code. Types and methods that are used through reflection in the code are transparent to the linker. If a situation like this exists in the code, decorate these types or methods with the Preserve attribute. This attribute basically informs the linker to be left out of the stripping-down process.

In the SDK version field, we set the iOS SDK version that will be used to compile the app. Setting it to Default automatically selects the highest SDK version installed on the system.

Note

When compiling for the simulator, turning the linker on is not suggested. This is because the compiler is not compiling the Xamarin.iOS assemblies in the iPhoneSimulator platform, hence, they are being used directly. Turning the linker on only causes compilation to take more time to complete. It has no effect in reducing the final app bundle size.

iOS application options

In the iOS Application window of the Build section in the project options, we set up three options:

  • The first option is Application Name. This is the name of the application bundle that will be displayed on the simulator, the device, and on the App Store. As we can see here, we can normally add spaces to the name.

  • The second option, Version, defines the version of the app. It is what will be displayed as the app's version when it is finally distributed through the App Store.

  • The third option, Deployment Target, is the minimum iOS version the app can be installed on.

There's more...

There are two more option windows. These are iOS Bundle Signing and iOS IPA Options. They will be discussed thoroughly in the recipes in Chapter 14, Deploying.

See also

  • The Preparing our app for the App Store recipe in Chapter 14, Deploying