据我所知,你不应该在一个类别中定义一个实例变量,如果你声明了一个属性,那只意味着你要对这个属性进行声明。吸气剂"方法
@interface CALayer (XQ)
@property NSString *demoVar;
- (void)demoFunc;
@end
@implementation CALayer (XQ)
- (void)demoFunc {
self.demoVar = @"cuteeeee";
NSLog(@"%@", self.demoVar);// when i call this method, it should crash, but the output is normal, why?
}
@end
对不起我的英语和短语,谢谢。
答案 0 :(得分:2)
CALayer.h
州的评论:
/** Property methods. **/
/* CALayer implements the standard NSKeyValueCoding protocol for all
* Objective C properties defined by the class and its subclasses. It
* dynamically implements missing accessor methods for properties
* declared by subclasses.
显然CALayer
处理类别中声明的属性与处理子类中声明的属性相同,因此它会为您动态实现访问器方法。