Home

kvo

KVO (Key‑Value Observing) is a mechanism provided by Apple’s Cocoa and Cocoa Touch frameworks that enables objects to be notified when a property of another object changes. It is built upon the key‑value coding (KVC) infrastructure, allowing observers to register for specific key paths and receive callbacks without requiring the observed object to implement explicit delegate methods or notifications.

To use KVO, an object adds itself as an observer of another object’s property by calling addObserver:forKeyPath:options:context:.

KVO is widely used for synchronizing UI elements with underlying data models, implementing bindings, and decoupling

The
observed
object
must
be
KVC‑compliant,
meaning
its
properties
are
accessible
through
standard
getter
and
setter
methods
or
are
dynamically
provided
via
the
runtime.
When
the
property’s
value
changes—typically
through
a
KVC‑compatible
setter—the
runtime
automatically
generates
willChangeValueForKey:/didChangeValueForKey:
calls
and
dispatches
an
observation
notification.
The
observer
receives
these
events
in
its observeValueForKeyPath:ofObject:change:context: method,
where
it
can
inspect
the
change
dictionary
for
old
and
new
values.
components
in
Model‑View‑Controller
architectures.
However,
developers
must
manage
observer
lifecycles
carefully;
failing
to
remove
observers
before
deallocation
can
cause
runtime
exceptions.
Since
iOS 11
and
macOS 10.13,
Apple
introduced
block‑based
KVO
APIs
that
simplify
registration
and
automatic
deregistration,
improving
safety
and
readability.