Is there any way to check the Objective-C version that I am using in my App
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.
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.
Xcode 13 doesnt have Objective C o…
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With