# Conditional compilation behavior for native iOS plug-ins

> Learn how to use conditional compilation to support different project types in your native source code plug-in.

Learn about the conditions you can check at different stages of build and runtime to create a generic plug-in that works across different targets.

Use conditional logic to create a generic plug-in that works across different targets. You can add checks in both native and C# code at different stages of the build and runtime process.

The following table outlines the conditions you can check at each stage:

| **Build stage**               | **Conditions and usage**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Xcode project generation**  | **Automatic plug-in integration**:When using the [plug-in Inspector](/engine/6000.7/manual/platform-specific/iphone/ios-developing/plugins-for-ios/ios-native-plugin-automated-integration.md), configure platform-specific settings to check for the Platform, SDK version, Architecture, and Project type, and use [Define Constraints](/engine/6000.7/manual/scripting/compilation-and-code-reload/script-compilation/assembly-definition-files/class-assembly-definition-importer.md#define-constraints) to check for the Unity version.**Manual plug-in file injection at post process with the PBXProject API:**&#x55;se [PostProcessBuildAttribute](/engine/6000.7/script-reference/unityeditor/callbacks/postprocessbuildattribute.md) with the [PBXProject API](/engine/6000.7/script-reference/unityeditor/ios/xcode/pbxproject.md) to add plug-ins based on Unity versions. You can check for:Platform ([BuildTarget](/engine/6000.7/script-reference/unityeditor/buildtarget.md))[SDK](/engine/6000.7/script-reference/unityeditor/playersettings/ios/sdkversion.md)[Architecture](/engine/6000.7/script-reference/unityeditor/playersettings/ios/simulatorsdkarchitecture.md)[Project type](/engine/6000.7/script-reference/unityeditor/xcodeprojecttype.md)Unity version[Application-unityVersion](/engine/6000.7/script-reference/unityengine/application/unityversion.md)Use Conditional C# defines, for example [`UNITY_2022_3_OR_NEWER`](/engine/6000.7/manual/scripting/compilation-and-code-reload/script-compilation/conditional-compilation/symbol-reference.md#Editor) |
| **Xcode project compilation** | In native code (Swift or Objective-C), you can check for:Platform, SDK, Architecture, and OS Version. Refer to [Running code on a specific platform or OS version](https://developer.apple.com/documentation/xcode/running-code-on-a-specific-version) (Apple Developer) for more information.Xcode Project Type using the `UNITY_XCODE_PROJECT_TYPE_SWIFT` define.In native Swift code, you can check for:Unity version, using the `UnityAPI` module version with `#if canImport(UnityAPI, _version: <UnityVersion>)`. Write `<UnityVersion>` without the release type or build number, for example `6000.7.0` for Unity 6000.7.0a5. The check matches that version and later. An Objective-C project type has no `UnityAPI` module, so the check is always false.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| **Application runtime**       | In native code, Swift or Objective-C, you can check for:Platform, SDK, Architecture, and OS Version. Refer to [Running code on a specific platform or OS version](https://developer.apple.com/documentation/xcode/running-code-on-a-specific-version) (Apple Developer) for more information.Xcode Project Type using the `UNITY_XCODE_PROJECT_TYPE_SWIFT` define.In a C# managed script, you can check for:[Platform](/engine/6000.7/script-reference/unityengine/application/platform.md)[Unity Version](/engine/6000.7/script-reference/unityengine/application/unityversion.md)[SDK](/engine/6000.7/script-reference/unityengine/ios/device/runsonsimulator.md)[OS Version](/engine/6000.7/script-reference/unityengine/ios/device/systemversion.md)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |

You can use preprocessor directives, such as `#if`, in both Swift and Objective-C to adjust behavior based on the target platform, architecture, or SDK version.

Unity's generated Xcode project can be one of two types: Swift or Objective-C. To distinguish between these types in your native code, use the `UNITY_XCODE_PROJECT_TYPE_SWIFT` preprocessor macro.

## Additional resources

* [Initialization paths for native iOS plug-ins](/engine/6000.7/manual/platform-specific/iphone/ios-developing/plugins-for-ios/ios-native-plugin-initialization.md)
* [Create a native plug-in for iOS](/engine/6000.7/manual/platform-specific/iphone/ios-developing/plugins-for-ios/ios-native-plugin-create.md)
