Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: unnecessary check for minimum deployment target

I have a Swift class which is linked against several targets with different deployment targets, the main project has iOS 7 minimum requirement and there is an extension with iOS 8 target.

Now when I compile project, the compiler throws warning on this line of code:

    if #available(iOS 8.0, *) { ... }

"Unnecessary check for 'iOSApplicationExtension'; minimum deployment target ensures guard will always be true"

I have checked build settings options and found no switch to kill swift warnings.

I tried to define iOSApplicationExtension version target separately by this line but without success:

    if #available(iOS 8.0, iOSApplicationExtension 8.0, *) { ... }

Is there any way to suppress this annoying message?

like image 208
Mousavian Avatar asked Sep 12 '15 01:09

Mousavian


People also ask

What is minimum deployment target?

That is the iOS deployment target or the minimum deployment target for iOS. It means that the application runs on any iOS device with iOS 14.3 or later installed. The values the dropdown menu lists depend on the version of Xcode you are using. Xcode 12, for example, no longer supports iOS 8.

What do you think is a sensible minimum iOS deployment target?

Suggested approach: Unless you have specific needs, a safe answer is Apple's: “the current version minus 1.” Note that e-commerce companies – i.e., companies that rely on users buying things through their app – are more likely to support a wider range of deployment targets, because even if only 5% of their users are on ...

How do I increase deployment target in Xcode?

Simply make a manual update to the Development target in the Xcode Pods file. It is your pod files deployment target iOS Version, not your project deployment target iOS Version, that is causing the issue; thus, you must update the deployment iOS version for your pods to anything more significant than 8.0 as well.


2 Answers

Found an ugly workaround to silence warning, but I hope there is a better way:

In iOS 8+ targets build settings, I defined a precompile flag in Build Settings -> Swift Compiler - Custom Flags -> Other Swift Flags:

-D iOS8target

Then I changed code to this way:

#if iOS8target
    // iOS 8+ compatible code
#else
    if #available(iOS 8.0, *) {
        // repeat iOS 8+ compatible code again!
    } else {
        // iOS 7 code
    }
#endif

It's not refactored and ugly, but it works!

UPDATE: There is a swift compiler switch -suppress-warnings to omit all warnings. But it also suppress useful warnings. Also if there is only one specific file which emits warnings, you can use -w flag in Building Phases pane. It will also suppress useful warnings but limited to one file.

like image 112
Mousavian Avatar answered Sep 28 '22 11:09

Mousavian


The next release of Cocoapod (after 0.39.0) should have this issue addressed. Check this for more details.

like image 42
Boon Avatar answered Sep 28 '22 11:09

Boon