2

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
Hackerman
  • 1,289
  • 1
  • 14
  • 29
  • XCode does not execute code by itself. You have to check for compiler version included in xCode or swift version that first appear in xCode 13. – Ptit Xav Feb 12 '22 at 08:37

3 Answers3

2

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 swift version you have set in your project.

Hackerman
  • 1,289
  • 1
  • 14
  • 29
0

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
Abhinav Mathur
  • 7,791
  • 3
  • 10
  • 24
0

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

Haseeb Javed
  • 1,769
  • 17
  • 20