Deprecation warning in Mac Catalyst but only in Objective-C, not in Swift

Viewed 3623

I'm using Xcode 11 on the GM build of Catalina (10.15). I'm working on building my iOS app for Mac Catalyst. My iOS app has a deployment target of iOS 11.

I have a simple line in a view controller such as:

self.modalInPopover = YES;

Compiles clean in iOS. When I switch to the "My Mac" destination, I get a deprecation warning:

'modalInPopover' is deprecated: first deprecated in macCatalyst 13.0

OK, fine. I can switch to the new method added in iOS 13:

if (@available(iOS 13.0, *)) {
    self.modalInPresentation = YES;
} else {
    self.modalInPopover = YES;
}

That should fix it but I still get the same deprecation warning on the use of modalInPopover in the else block.

What's odd is that the corresponding Swift code does not give any warnings. Only the Objective-C code continues to give the warning.

if #available(iOS 13, *) {
    self.isModalInPresentation = true
} else {
    self.isModalInPopover = true
}

I even tried updating the @available to:

if (@available(iOS 13.0, macCatalyst 13.0, *)) {

but that didn't change anything.

The following disaster solves the problem but it shouldn't be needed:

#if TARGET_OS_MACCATALYST
    self.modalInPresentation = YES;
#else
    if (@available(iOS 13.0, *)) {
        self.modalInPresentation = YES;
    } else {
        self.modalInPopover = YES;
    }
#endif

Am I missing something or is this an Xcode bug? How can I eliminate the deprecation warning in Objective-C without duplicating code using #if TARGET_OS_MACCATALYST which isn't need in Swift.

2 Answers

My iOS app has a deployment target of iOS 11.

That’s why. To see the deprecation warning in Swift you would need to say isModalInPopover not in an available clause with a deployment target of iOS 13.

For the Catalyst build, you're not backward compatible (there is no backward) so it's as if this were an iOS 13 deployment target, and you see the warning.

Related