Important: Not all classes are KVO-compliant for all properties. You can ensure your own classes are KVO-compliant by following the steps described in “KVO Compliance.” Typically properties in Apple-supplied frameworks are only KVO-compliant if they are documented as such.
This statement leaves me confused. Can't we use KVO for UIKit objects at all? I don't remember seeing any property being documented as KVO compliant. Despite saying otherwise, I am able to use KVO with many properties. Does this mean that I can't rely on it?
Any insight into this would be appreciated.
UIKit is mostly NOT KVO compliant. This is mostly because
UIView
acts as high-level wrapper forCALayer
, so when you eg. change theframe
property of anUIView
, it will change the layersframe
but leave eg. thebounds
property of theUIView
untouched, so no observer will be triggered for theview.bounds
path, because it never really changes. And this leads to non KVO compliance.Only if the property is marked as KVO compliant can you rely on this, otherwise it will not work or break in some weird cases.