需要创建一个带有新变量的类别(类型为NSArray).
OriginalClass Extension.h:
@interface OriginalClass (Extension) { NSArray *_array; } @property (nonatomic,retain) NSArray *array; @end
但是我得到了错误:无法在@interface或@protocol中声明变量.
请帮忙解决问题.
解决方法
正如另一方所说,你不能.虽然有H2CO3指出,你可以使用
associative references.在
Apple Documents:
Note that a category can’t declare additional instance variables for@H_403_16@ the class; it includes only methods. However,all instance variables@H_403_16@ within the scope of the class are also within the scope of the@H_403_16@ category. That includes all instance variables declared by the class,@H_403_16@ even ones declared @private.