Popular Tags

Who's online

There are currently 0 users and 73 guests online.

User login

Key-Value Observing (KVO) and Key-Value Coding (KVC) are two very important concepts in Objective-C and are vital if you want to use technologies such as bindings or Core Data in your projects.

Keys and Values
Objects in Objective-C can have instance variables, or attributes, that help define the state of the object. A "Recipe" object might have instance variables of "name" (an NSString), "preparationTime" (perhaps an NSTimeInterval), a list of "ingredients" (probably an NSArray pointing to separate Ingredient objects), and so forth.

The name of these variables ("name", "preparationTime", "ingredients") is the key, while the data they hold are the value. The idea is roughly equivalent to an NSDictionary, which holds data (values) based on reference objects (keys).

Keys, when talking about KVO and KVC, are always strings. That is, they are a sequence of characters that match the name of the variable. @"name" would be the key of the "name" property of the recipe, and its value might be something like "Dave's Amazing Guacamole".

Key-Value Observing
This ability to refer to variables by their key is very powerful. It was the driving concept behind bindings.

Related Articles:
Introduction to Key-Value Coding Programming Guide

Your rating: None Average: 2.2 (6 votes)

Search

UPDATES

The site has recently been updated. You may notice some of the following issues:

  • Some URLs no longer work. Please use the search box.
  • File uploads should now be working. If you experience problems, please contact us.