Amit
Amit

Reputation: 645

@available api check not works in Xcode 8

I am writing objective-c code in Xcode 8.0, for API availability I am using

 if (@available(iOS 11, *)) {
        // iOS 11 (or newer) ObjC code
 } else {
        // iOS 10 or older code
 }

Unfortunately compiler fires:

unrecognised platform name iOS

Why?

Upvotes: 0

Views: 3205

Answers (1)

Cœur
Cœur

Reputation: 38717

As I wrote at How to check iOS version?:

  • @available was added in Xcode 9
  • #available was added in Xcode 7

If you need to test availability for multiple versions of Xcode, you can detect Xcode 9 with #ifdef __MAC_10_13 or, better, #if __clang_major__ >= 9, as below:

#if __clang_major__ >= 9
    // Xcode 9+
    if (@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)) {
        // iOS 8+
    }
#else
    // Xcode 8-
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_9_2) {
        // iOS 8+
    }
#endif
    else {
        // iOS 7-
    }

Real case example taken from: https://github.com/ZipArchive/ZipArchive/blob/master/SSZipArchive/SSZipArchive.m

Upvotes: 5

Related Questions