We'd like to find a way to write iOS-only Swift code blocks in code that supports multiple Apple platforms and runs without warnings on both Xcode 14 and 15.
It's complicated by the fact that #if os(iOS)
evaluates to true for visionOS
so the test #if os(iOS) && !os(visionOS)
is needed to build iOS-only code on Xcode 15. However, this generates a warning on Xcode 14 since visionOS
is not recognized.
#if os(iOS) && (swift(<5.9) || !os(visionOS))
also generates warnings on Xcode 14.
We've found that the following runs warning free on both:
#if swift(>=5.9)
#if os(iOS) && !os(visionOS)
code block
#endif
#else
#if os(iOS)
code block
#endif
#endif
But this is ugly since the code block needs to be duplicated. Is there a better way?