Introduction to Key Value Observing

What is Key-Value Observing (KVO)?

  • Key-Value Observing provides a mechanism that allows objects to be notified of changes to specific properties of other objects. It is particularly useful for communication between model and controller layers in an application.
  • Key-Value Observing is heavily used in OS X development in bindings and form a significant portion of UI design.
  • Key-Value Observing “broadcasts” a notification whenever a property is modified, and any class can receive those notifications and handle changes as necessary.
  • Key-Value Observing allows one object to respond to changes of another object's properties by registering the "Observer" with the "target" object.
  • Key-Value Observing helps to decouple your classes from each other, allowing more flexible and re-usable code, especially as your code grows large and you have many sets of MVC objects.
  • Key-Value Observing is primarily used when you have one model object backing multiple controllers, in which case we can use KVO to update the model when any controller changes its data.


How Key-Value Observing Works?



Benefits of Key-Value Observing (KVO)?

KVO’s primary benefit is that you don’t have to implement your own scheme to send notifications every time a property changes. Its well-defined infrastructure has framework-level support that makes it easy to adopt—typically you do not have to add any code to your project. 

In addition, the infrastructure is already full-featured, which makes it easy to support multiple observers for a single property, as well as dependent values.

SEE ALSO


No comments:

Post a Comment