关于KVO的理解
Key-Value Observing
非常像GDB里面的watchpoint,注册以后,每次值的变化,都会调用
-(void) observeValueForKeyPath:ofObject:change:context:;
来通知,从而有机会检查目前这个值是多少?要不要敢点什么事情?
完成KVO,要满足三条:
-
The observed class must be key-value observing compliant for the property that you wish to observe.
-
You must register the observing object with the observed object, using the method
addObserver:forKeyPath:options:context:
. -
The observing class must implement
observeValueForKeyPath:ofObject:change:context:
.
第一,你添加的KVO,要满足它的要求。一般要继承于nsobject,单独给他一个cgfloat,它无法监控。这跟GDB是不一样的。
第二,得注册上。不然没法监控
第三,得有处理函数,不然白监控了。