Auto property synthesis will not synthesize property 'request' because it is 'readwrite' but it will be synthesized 'readonly' via another property
Auto property synthesis will not synthesize property 'response' because it is 'readwrite' but it will be synthesized 'readonly' via another property
在AFHTTPRequestOperation中定义了:
@property (readwrite, nonatomic, strong) NSURLRequest *request;
@property (readwrite, nonatomic, strong) NSHTTPURLResponse *response;
就是这样的代码,会让
但你知道 super-class 的实现,也会将这个 property 改成
你要告诉 compiler,要它不用担心。那要怎么告诉 compiler 呢?你需要的是
@implementation AFHTTPRequestOperation
@dynamic response;
@dynamic request;
@end
简单解释@dynamic:
写个一个类目,想给这个类加个属性。
@dynamic告诉编译器,属性的setter与getter方法由用户自己实现,不自动生成。(当然对于readonly的 属性只需提供getter即可)。假如一个属性被声明为@dynamic var,然后你没有提供@setter方法和@getter方法,编译的时候没问题,但是当程序运行到instance.var =someVar,由于缺setter方法会导致程序崩溃;或者当运行到 someVar = var时,由于缺getter方法同样会导致崩溃。编译时没问题,运行时才执行相应的方法,这就是所谓的动态绑定。