David Andreoletti David Andreoletti - 1 month ago 6
Objective-C Question

How to get an Objective-C property's declared attributes at runtime?

Assuming an Objective-C Property declared as follow:

@property (nonatomic, strong) id foobar;


The Objective-C runtime provides
objc_property_attribute_t
which should contain/encode the value of each property's declared attribute (
nonatomic
, etc ...)

However, I could not find in the Objective-C runtime documentation an API to access the property's attributes, namely in my example:
nonatomic and strong
and objc_property_t is an opaque type.

Hence my question, how to get an Objective-C property's declared attributes at runtime ?

Answer

Based on @Larme's link, the API to get an Objective-C property attributes at runtime is property_getAttributes defined in <objc/runtime.h>