Subscribe to our YouTube Channel for more Videos

Using Conditional Compilation in Xamarin Shared Project for iOS

There are times when you might want to perform an action that is specific to a device in the Xamarin Shared Project.

For example , assume that you have to set the string named title within the Xaml page present in the Xamarin Shared Project only for iOS devices to a specific text, you can use the conditional compilation directive as shown below.

string Title = "";
#if __IOS__ 
   Title = "This is an iOS App"; 

Where did we get this __IOS__ directive from ?

Right click on the <AppName>.iOS project in the Solution Explorer and navigate to the Project properties Window.

Select Build from within the iOS project properties screen and you would fine the __IOS__ in the Conditional compilation symbols textbox as shown.


Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.