Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know the Objective-C language version in Xcode

Is there any way to check the Objective-C version that I am using in my App

like image 430
Jobin Jose Avatar asked Jun 03 '16 07:06

Jobin Jose


People also ask

Does Xcode use Objective-C?

Objective-C is an object-oriented programming language used by Apple since the 90. It combines the advantages of two earlier languages - C and Smalltalk. In 1996 Apple overtook NeXT, which developer tools would use Objective-C. These tools were later included in Xcode.

What is Objective-C in Xcode?

Objective-C is the programming language that is used to write applications for Apple's iOS and OS X operating systems. The Objective-C programming language is based on C, but it adds support for object-oriented programming. All Objective-C programming is done with the Foundation framework.

Does Xcode 13 support Objective-C?

Xcode 13 doesnt have Objective C o…


1 Answers

The Objective-C level of language support is defined by the version of Clang used to compile the code, which is itself very close to the version of Xcode.

#if __clang_major__ >= 11
    NSLog(@"My Objective-C language support is what Apple Clang/Xcode 11.x can support.");
    // This language version supports the additional features/fixes written under "Apple Clang Compiler"
    // https://developer.apple.com/documentation/xcode_release_notes/xcode_11_release_notes
    // Notably this version adds Objective-C support to:
    // - `[[clang::no_destroy]]` and `[[clang::always_destroy]]`

#elif __clang_major__ >= 10
    NSLog(@"My Objective-C language support is what Apple Clang/Xcode 10.x can support.");
    // This language version supports the additional features/fixes written under "Apple Clang Compiler"
    // https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
    // Notably this version adds macro support to:
    // - detect most builtin pseudo-functions with `__has_builtin`

#elif __clang_major__ >= 9
    NSLog(@"My Objective-C language support is what Apple Clang/Xcode 9.x can support.");
    // This language version supports the additional features/fixes written under "Apple LLVM Compiler and Low-Level Tools"
    // https://developer.apple.com/library/archive/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW878
    // Notably this version adds Objective-C support for:
    // - the `@available` language feature

#elif __clang_major__ >= 8
    NSLog(@"My Objective-C language support is what Apple Clang/Xcode 8.x can support.");
    // This language version supports the additional features/fixes written under "Objective-C and C++"
    // https://developer.apple.com/library/archive/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW78
    // Notably this version adds Objective-C support for:
    // - the `@property (class)` language feature

#elif __clang_major__ >= 7
    NSLog(@"My Objective-C language support is what Apple Clang/Xcode 7.x can support.");
    // This language version supports the additional features/fixes written under "Objective-C"
    // https://developer.apple.com/library/archive/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW326
    // Notably this version adds Objective-C support for:
    // - `CF_RETURNS_NOT_RETAINED` and `CF_RETURNS_RETAINED`
    // - `__kindof`
    // - `_Nullable`, `_Nonnull`, and `_Null_unspecified`
    // - Lightweight generics like `NSArray<UIImage *> *` and `NSDictionary<NSString *, NSURL *>`

#elif __clang_major__ >= 6
    NSLog(@"My Objective-C language support is what Apple Clang/Xcode 6.x can support.");
    // This language version supports the additional features/fixes written at:
    // https://developer.apple.com/library/archive/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW453

#else
    NSLog(@"My Objective-C language support is so old that I won't even be allowed to publish this on any App Store nowadays.");

#endif

You may also use __clang_minor__ if you need more precision for the version being used.

Whenever possible, it is advised to use __has_builtin to check the availability of Objective-C language features instead of __clang_major__ and __clang_minor__.

Some notable other older historical language features that you shouldn't even bother testing for availability anymore:

  • NS_ENUM and NS_OPTIONS were added in Xcode 4.5
  • NSDictionary and NSArray subscripting were added in Xcode 4.4 / 4.5
  • @YES and @NO literals were added in Xcode 4.4 / 4.5
  • NSNumber, NSDictionary and NSArray literals were added in Xcode 4.4
  • @autoreleasepool blocks were added in Xcode 4.2
  • "Objective-C 2.0" is something VERY old (Xcode 2.x)

Lastly "Modern Objective-C" just refers to any currently available Xcode support for Objective-C.

Related:

  • How can I reliably detect the version of clang at preprocessing time?
like image 110
Cœur Avatar answered Sep 20 '22 15:09

Cœur