1 // 第二步:实现回调
2 - (void)observeva lueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
3 {
4
5 NSLog(@"keyPath = %@", keyPath);
6 NSLog(@"object = %@", object);
7 NSLog(@"change = %@", change);
8
9 // 可以进行刷新UI的操作
10 }
1 // 第二步:实现回调
2 - (void)observeva lueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
3 {
4
5 NSLog(@"keyPath = %@", keyPath);
6 NSLog(@"object = %@", object);
7 NSLog(@"change = %@", change);
8
9 // 可以进行刷新UI的操作
10 }
1 // 视图将要消失的时候
2 - (void)viewWillDisappear:(BOOL)animated
3 {
4 // 在不需要观察者的时候需要把它删除
5 [self removeObserver:self forKeyPath:@"array"];
6 }