因为Cocoa是严格遵循MVC模式的,所以KVO在观察Modal的数据变化时很有用。那么KVO是怎么实现的呢,苹果官方文档上说的比较简单:“Automatic key-value observing is implemented using a technique called isa-swizzling.” “When an observer is registered for an attribute of an object the isa pointer of the observed object is modified, pointing to an intermediate class rather than at the true class. As a result the value of the isa pointer does not necessarily reflect the actual class of the instance.” 就是说在运行时会生成一个派生类,在这个派生类中重写基类中任何被观察属性的 setter 方法,用来欺骗系统顶替原先的类。