Created
June 9, 2022 15:28
-
-
Save ole/06e4582615a378bce1499bdf58e3c404 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I learned about `#if canImport(module, _version: x.y)` from Tony Allevato: | |
// https://forums.swift.org/t/pitch-sdk-conditional-code/52642/4 | |
// | |
// Does this work reliably? I have no idea! | |
// I have only done some quick experiments in a playground. | |
// | |
// The Foundation version in Xcode 14.0b1 is: | |
// - in iOS's Foundation.swiftinterface: 1932.104 | |
// - in macOS's Foundation.swiftinterface: 1932.401 | |
// | |
// Checking for the smaller number seems to work for both OSes. | |
#if canImport(Foundation, _version: 1932.104) | |
print("We're using the macOS 13/iOS 16 base SDK") | |
#elseif canImport(Foundation) | |
print("We're using an older base SDK") | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you run this code in Xcode 14.0b1, you'll enter the first branch. If you run it in Xcode 13.4, you'll enter the second branch. Tested in a macOS and iOS playground, respectively. I haven't tested this in a real project.