需要创建一个带有新变量的类别(类型为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
the class; it includes only methods. However,all instance variables
within the scope of the class are also within the scope of the
category. That includes all instance variables declared by the class,
even ones declared @private.