17

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?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Mousavian
  • 1,435
  • 1
  • 15
  • 23
  • 1
    see this link may be help with you https://forums.developer.apple.com/thread/15030 – Anbu.Karthik Sep 12 '15 at 02:24
  • 1
    Most likely your minimum deployment target for the extension is iOS 8. This will mean that `#available(iOS 8.0, 0)` will always be true, i.e. it's unnecessary. – saagarjha Sep 12 '15 at 04:04
  • @ILikeTau app extensions only work on iOS 8+. that's why I did this. – Mousavian Sep 12 '15 at 09:35
  • Yes, but your deployment target is the same, so you don't need the `if`. – saagarjha Sep 12 '15 at 16:53
  • 1
    @ILikeTau my main app minimum req is iOS 7, extension is iOS8. both of them are using same file/class. so I have to check version for main app. can't omit it. – Mousavian Sep 12 '15 at 18:57
  • I'd like this fixed / addressed too. I'm running into this when using a cocoapod that supports older iOS targets than my app. Maybe file a radar? – Mike Vosseller Nov 20 '15 at 12:14
  • I have the same problem using a file that is not mine (from https://github.com/Alamofire/Alamofire). – Martin Delille Apr 23 '16 at 12:28

3 Answers3

2

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.

Mousavian
  • 1,435
  • 1
  • 15
  • 23
1

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

Boon
  • 40,656
  • 60
  • 209
  • 315
0

Please check your deployment target into your General and set from 9.0 to 7.0 or less. this warning will remove automatically.

Ravi Kumar
  • 1,356
  • 14
  • 22
  • there are different projects which use same source file. can't change it. some need to be 8+ – Mousavian Dec 28 '15 at 19:55
  • if there are deprecated from ios8+ then you have to code for both with old and new class. there is a no option. try to set deployment target to 8. – Ravi Kumar Dec 29 '15 at 05:18