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

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn about the error message “FileOpenAccessDenied – You do not have permissions to open this file...
  • December 3, 2024
You might have had a situation where your code once worked fine in ASP.NET application but now throws the below...
  • December 3, 2024
C# uses the flower bracket “{” and “}” to identify the block or scope of the function or program ....
  • December 3, 2024