Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 333
rmaddy Avatar asked Oct 07 '19 01:10

rmaddy


2 Answers

You can use this to check whenever you running it on different platforms:

#if targetEnvironment(macCatalyst)
    print("UIKit running on macOS")
#elseif os(watchOS)
    print("Running on watchOS")
#else
    print("Your regular code")
#endif

also it should remove the warning. More details can be found here: https://www.hackingwithswift.com/example-code/catalyst/how-to-detect-your-ios-app-is-running-on-macos-catalyst

like image 140
Oleg Avatar answered Nov 08 '22 12:11

Oleg


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.

like image 1
matt Avatar answered Nov 08 '22 11:11

matt