iosxcodexcconfigmac-catalyst

Differentiate between iOS and macCatalyst in xcconfig file


In an xcconfig file it's possible to use sdk and arch specifiers. For example:

BUILD_SETTING_NAME[sdk=sdk] = value for specified sdk
BUILD_SETTING_NAME[arch=architecture] = value for specified architecture

How can I use this to use a different value when building for macCatalyst ("UIKit for Mac")?


Solution

  • OK, it turns out to be easier than I thought. You can simply do this in your xcconfig file:

    SOME_PLATFORM_DEPENDENT_VALUE = "use this on iOS";
    SOME_PLATFORM_DEPENDENT_VALUE[sdk=macosx*] = "use this on macOS including macCatalyst";
    

    On the first line you set the value for all platforms. On the second line you set the value for a specific SDK. The specific value takes precedence over the "general" value.

    That's it! You can learn more about these different options in this great NSHipster article.