Reputation: 288
Is there any way to check the Objective-C version that I am using in my App
Upvotes: 5
Views: 2441
Reputation: 38667
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.5NSDictionary
and NSArray
subscripting were added in Xcode 4.4 / 4.5@YES
and @NO
literals were added in Xcode 4.4 / 4.5NSNumber
, NSDictionary
and NSArray
literals were added in Xcode 4.4@autoreleasepool
blocks were added in Xcode 4.2Lastly "Modern Objective-C" just refers to any currently available Xcode support for Objective-C.
Related:
Upvotes: 6
Reputation: 410
There are two versions of the Objective-C runtime—“modern” and “legacy”. iPhone applications and 64-bit programs on OS X v10.5 and later use the modern version of the runtime.check here
All major features introduced in objective-c, You can check here
Upvotes: 1