When I declare a property, I can put various attributes in the declaration, which will have special meaning for the compiler:
@property (nonatomic, retain) NSNumber *consumption;
Here, nonatomic and retain are attributes. Is it possible to add a custom attribute, and be able to check for the existance of this attribute at runtime ? For instance:
@property (nonatomic, retain, test) NSNumber* consumption;
I am basically using for a construct that can replace the use of attributes as I know them from C#/.NET – so alternative suggestions are also welcomed.
You can’t add attributes to
@property()without modifying the compiler.Note that, in general, grubbing even the existing attributes of
@propertydeclarations at runtime is quite thoroughly discouraged. The runtime does offer an API via which you can do so, but it is not intended for general purpose use and will likely change in the future.