Conditionally compile newer API with older XCode

I made an update to my app's code to make use of the new Contact access limited permission (CNAuthorizationStatusLimited), like so:

  if (@available(iOS 18.0, *)) {
    switch ([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]) {       
      case CNAuthorizationStatusLimited:
<snip>

However, later I discovered there's another totally unrelated issue which only manifests when the app is built with XCode 16. It isn't a trivial change to workaround, so for now I would like to make a release to the app store which makes use of the new CNAuthorizationStatusLimited status but is built using XCode 15. However, building with XCode 15 results in a "Use of undeclared identifier 'CNAuthorizationStatusLimited' error.

If the code were making use of a new API, I could workaround using a selector for example, however as this is an enum, is there Is there any workaround possible for this - or its just not possible to build using XCode 15 and the source code contain references to CNAuthorizationStatusLimited?

Xcode 15 doesn't support the iOS 18 SDK, so you cannot build iOS 18 apps with an Xcode earlier than version 16.

There is no workaround for that.

I suppose you should be asking how to fix the non-trivial issue with building your app in Xcode 16?

Hang on, maybe I misunderstood this. Can you use something like the respondsToSelector? I have no idea if it's there in Swift 5/6, but this SO page gives an example of how to use it: https://stackoverflow.com/questions/24167791/what-is-the-swift-equivalent-of-respondstoselector

Conditionally compile newer API with older XCode
 
 
Q