例如,
@interface MyClass : NSObject
@property(copy) NSMutableArray *array;
@end
@implementation MyClass
@end
@implementation OtherClass {
MyClass *me;
}
- (instancetype)init {
self = [super init];
[me addObserver:self forKeyPath:@"array" options:Old|New context:NULL];
return self;
}
@end
以上代码中,当 array 指针指向新的 NSMutableArray 时,KVO会被触发。
那么问题来了,当 array 的内容变化时,例如发生 [array addObject:@1024] 这样的情况时,KVO会触发吗?
这个方法可以触发KVO