One example of an Apple API that relies on runtime functions like those above is Key-Value Observing. When you learned about KVO in Chapter Chapter 36, you learned that an observer is automatically notified of a change in a property if the affected object’s accessors are used.
At runtime, when an object is sent the addObserver:forKeyPath:options:context: message, this method:
determines the class of the observed object and defines a new subclass of that class using the objc_allocateClassPair function
changes the object’s isa pointer to point to the new subclass (effectively changing the type of the object)
overrides the observed object’s accessors to send KVO messages
Figure A.1 KVO dynamic subclass