Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Macro to detect availability of class properties in Objective-C

Xcode 8 introduces Objective-C class properties and I would like to add one to an Objective-C library.

However I would like the library to still compile with Xcode 7. Is there an availability check I can do at compile time?

Something like

#if __hasFeature(objc_class_properties)
@property (class, readonly, nonatomic) MySingletonClass *shared;
#endif

What does work is:

#if __clang_major__ >= 8

…but I'd like to check for feature availability rather than CLANG version.

like image 307
Frank Schmitt Avatar asked Dec 05 '25 07:12

Frank Schmitt


1 Answers

Searching the LLVM source code I found:

#if __has_feature(objc_class_property)

…which works perfectly.

like image 154
Frank Schmitt Avatar answered Dec 09 '25 21:12

Frank Schmitt