Home > other >  Only run code if on a certain version of Xcode
Only run code if on a certain version of Xcode

Time:02-15

I'm making a library that uses the variants variable of AVAsset. That's less important; the significant part is that it has an Xcode 13 requirement. This library may be used by apps running Xcode 12. Is there a compiler flag that can run code only if on a certain version of Xcode?

Something like how you would do this for a Swift version:

#if swift(>=5.0)
   // code
#else
   // code
#endif

I'd want to do

#if xcode(>=13.0)

   // use variants

#endif

CodePudding user response:

I found that #if compiler(>=5.5) works here. Note, this is different than if swift(>=5.5), which will not necessarily work depending on the language you have set in your project.

CodePudding user response:

From what I know, there’s no way of directly checking the Xcode version. However, Xcode 13 supports iOS 15, Xcode 12 doesn’t. You can use that as a workaround to check if Xcode version is 13 or higher.

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // iOS 15 or greater
// Xcode 12 will not see this code.
#else
// Xcode 12 and lower will see this
#endif

CodePudding user response:

Actual Post Link

Xcode 12.5   :      Swift version 5.4.2

Xcode 12.3   :      Swift version 5.3.2

Xcode 12.2   :      Swift version 5.3.1

Xcode 11.6   :      Swift version 5.2.4

Xcode 11.5   :      Swift version 5.2.4

Xcode 11.4   :      Swift version 5.2

Xcode 11.3   :      Swift version 5.1.3

Xcode 11.2.1 :      Swift version 5.1.2

Xcode 11.1   :      Swift version 5.1

And then here's how to check:

#if compiler(>=5) //4.2, 3.0, 2.0 replace whatever swift version you wants to check
print("Hello Swift 5")
#endif

All the best

  • Related