3

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
1
  • 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. Commented Feb 12, 2022 at 8:37

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

I believe this is for objective-c only, not swift
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 😊

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.