我可以在Objective-C中为成员指定自定义属性吗?

dri*_*iis 11 objective-c

当我声明一个属性时,我可以在声明中放入各种属性,这对编译器有特殊意义:

@property (nonatomic, retain) NSNumber *consumption;
Run Code Online (Sandbox Code Playgroud)

在这里,nonatomicretain是属性.是否可以添加自定义属性,并能够在运行时检查此属性的存在性?例如:

@property (nonatomic, retain, test) NSNumber* consumption;
Run Code Online (Sandbox Code Playgroud)

我基本上使用的构造可以替换属性的使用,因为我从C#/ .NET中知道它们 - 因此也欢迎其他建议.

bbu*_*bum 4

@property()如果不修改编译器,就无法添加属性。

请注意,一般来说,@property完全不鼓励在运行时修改声明的现有属性。运行时确实提供了一个 API,您可以通过它来执行此操作,但它不适合一般用途,并且将来可能会发生变化。