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"; 
 
#endif 

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.

image

Leave a Reply