Important: The information in this document is obsolete and should not be used for new development.
(informal protocol)
Package | com.apple.cocoa.foundation |
Companion guide |
The NSKeyValueCoding interface defines a mechanism in which the properties of an object are accessed indirectly by name (or key), rather than directly through invocation of an accessor method or as instance variables. Thus, all of an object’s properties can be accessed in a consistent manner.
The basic method for accessing an object’s value is valueForKey
, which returns the value for the property identified by the specified key. The default implementation uses the accessor methods normally implemented by objects (or to access instance variables directly if need be).
Sets the value for the property identified by key to value.
public abstract void takeValueForKey
(Object value, String key)
The default implementation works as follows:
Searches for a public accessor method of the form set
Key, invoking it if there is one.
If a public accessor method is not found, searches for a private accessor method of the form _set
Key, invoking it if there is one.
If an accessor method is not found takeValueForKey
searches for an instance variable based on key and sets the value directly. For the key “lastName”, this would be _lastName
or lastName
.
Returns the value for the property identified by key.
public abstract Object valueForKey
(String key)
The default implementation works as follows:
Searches for a public accessor method based on key. For example, with a key of “lastName”, valueForKey
looks for a method named getLastName
or lastName
.
If a public accessor method is not found, searches for a private accessor method based on key (a method preceded by an underbar). For example, with a key of “lastName”,
valueForKey
looks for a method named _getLastName
or _lastName
.
If an accessor method is not found valueForKey
searches for an instance variable based on key and returns its value directly. For the key “lastName”, this would be _lastName
or lastName
.
These constants define the available array operators. See “Set and Array Operators” for more information.
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)