Protocol: NSKeyValueCoding
Overview
The NSKeyValueCoding informal protocol defines a mechanism by which you can access the properties of an object 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.Returns a Boolean value that indicates whether the key-value coding methods should access the corresponding instance variable directly on finding no accessor method for a property.Returns a dictionary containing the property values identified by each of the keys in a given array.Returns a mutable array proxy that provides read-write access to an ordered to-many relationship specified by a given key.Returns a mutable array that provides read-write access to the ordered to-many relationship specified by a given key path.Returns a mutable ordered set that provides read-write access to the uniquing ordered to-many relationship specified by a given key.Returns a mutable ordered set that provides read-write access to the uniquing ordered to-many relationship specified by a given key path.Returns a mutable set proxy that provides read-write access to the unordered to-many relationship specified by a given key.Returns a mutable set that provides read-write access to the unordered to-many relationship specified by a given key path.Invoked by setValue:forKey: when it’s given a nil value for a scalar value (such as an int or float).Sets the property of the receiver specified by a given key to a given value.Sets the value for the property identified by a given key path to a given value.Invoked by setValue:forKey: when it finds no property for a given key.Sets properties of the receiver with values from a given dictionary, using its keys to identify the properties.Returns a Boolean value that indicates whether the value specified by a given pointer is valid for the property identified by a given key.Returns a Boolean value that indicates whether the value specified by a given pointer is valid for a given key path relative to the receiver. Returns the value for the property identified by a given key.Returns the value for the derived property identified by a given key path.Invoked by valueForKey: when it finds no property corresponding to a given key.This constant defines the name of an exception raised when a key value coding operation fails.These constants are keys into an NSUndefinedKeyException userInfo dictionaryThese constants define the available array operators. See Set and Array Operators for more information.
Class Method Summary (collapse)
-
+ accessInstanceVariablesDirectly
Returns a Boolean value that indicates whether the key-value coding methods should access the corresponding instance variable directly on finding no accessor method for a property.
Instance Method Summary (collapse)
-
- dictionaryWithValuesForKeys:
Returns a dictionary containing the property values identified by each of the keys in a given array.
-
- mutableArrayValueForKey:
Returns a mutable array proxy that provides read-write access to an ordered to-many relationship specified by a given key.
-
- mutableArrayValueForKeyPath:
Returns a mutable array that provides read-write access to the ordered to-many relationship specified by a given key path.
-
- mutableOrderedSetValueForKey:
Returns a mutable ordered set that provides read-write access to the uniquing ordered to-many relationship specified by a given key.
-
- mutableOrderedSetValueForKeyPath:
Returns a mutable ordered set that provides read-write access to the uniquing ordered to-many relationship specified by a given key path.
-
- mutableSetValueForKey:
Returns a mutable set proxy that provides read-write access to the unordered to-many relationship specified by a given key.
-
- mutableSetValueForKeyPath:
Returns a mutable set that provides read-write access to the unordered to-many relationship specified by a given key path.
-
- setNilValueForKey:
Invoked by setValue:forKey: when it’s given a nil value for a scalar value (such as an int or float).
-
- setValue:forKey:
Sets the property of the receiver specified by a given key to a given value.
-
- setValue:forKeyPath:
Sets the value for the property identified by a given key path to a given value.
-
- setValue:forUndefinedKey:
Invoked by setValue:forKey: when it finds no property for a given key.
-
- setValuesForKeysWithDictionary:
Sets properties of the receiver with values from a given dictionary, using its keys to identify the properties.
-
- validateValue:forKey:error:
Returns a Boolean value that indicates whether the value specified by a given pointer is valid for the property identified by a given key.
-
- validateValue:forKeyPath:error:
Returns a Boolean value that indicates whether the value specified by a given pointer is valid for a given key path relative to the receiver.
-
- valueForKey:
Returns the value for the property identified by a given key.
-
- valueForKeyPath:
Returns the value for the derived property identified by a given key path.
-
- valueForUndefinedKey:
Invoked by valueForKey: when it finds no property corresponding to a given key.
Class Method Details
+ (Boolean) accessInstanceVariablesDirectly
Returns a Boolean value that indicates whether the key-value coding methods should access the corresponding instance variable directly on finding no accessor method for a property. The default returns YES. Subclasses can override it to return NO, in which case the key-value coding methods won’t access instance variables.
Instance Method Details
- (Hash) dictionaryWithValuesForKeys(keys)
Returns a dictionary containing the property values identified by each of the keys in a given array. The default implementation invokes valueForKey: for each key in keys and substitutes NSNull values in the dictionary for returned nil values.
- (Array) mutableArrayValueForKey(key)
Returns a mutable array proxy that provides read-write access to an ordered to-many relationship specified by a given key. Objects added to the mutable array become related to the receiver, and objects removed from the mutable array become unrelated. The default implementation recognizes the same simple accessor methods and array accessor methods as valueForKey:, and follows the same direct instance variable access policies, but always returns a mutable collection proxy object instead of the immutable collection that valueForKey: would return. The search pattern that mutableArrayValueForKey: uses is described in Accessor Search Implementation Details in Key-Value Coding Programming Guide.
- (Array) mutableArrayValueForKeyPath(keyPath)
Returns a mutable array that provides read-write access to the ordered to-many relationship specified by a given key path. See mutableArrayValueForKey: for additional details.
- (NSMutableOrderedSet) mutableOrderedSetValueForKey(key)
Returns a mutable ordered set that provides read-write access to the uniquing ordered to-many relationship specified by a given key. Objects added to the mutable set proxy become related to the receiver, and objects removed from the mutable set become unrelated. The default implementation recognizes the same simple accessor methods and set accessor methods as valueForKey:, and follows the same direct instance variable access policies, but always returns a mutable collection proxy object instead of the immutable collection that valueForKey: would return. The search pattern that mutableOrderedSetValueForKey: uses is described in Accessor Search Implementation Details in Key-Value Coding Programming Guide.
- (NSMutableOrderedSet) mutableOrderedSetValueForKeyPath(keyPath)
Returns a mutable ordered set that provides read-write access to the uniquing ordered to-many relationship specified by a given key path. See mutableOrderedSetValueForKey: for additional details.
- (NSMutableSet) mutableSetValueForKey(key)
Returns a mutable set proxy that provides read-write access to the unordered to-many relationship specified by a given key. Objects added to the mutable set proxy become related to the receiver, and objects removed from the mutable set become unrelated. The default implementation recognizes the same simple accessor methods and set accessor methods as valueForKey:, and follows the same direct instance variable access policies, but always returns a mutable collection proxy object instead of the immutable collection that valueForKey: would return. The search pattern that mutableSetValueForKey: uses is described in Accessor Search Implementation Details in Key-Value Coding Programming Guide.
- (NSMutableSet) mutableSetValueForKeyPath(keyPath)
Returns a mutable set that provides read-write access to the unordered to-many relationship specified by a given key path. See mutableSetValueForKey: for additional details.
- (Object) setNilValueForKey(key)
Invoked by setValue:forKey: when it’s given a nil value for a scalar value (such as an int or float). Subclasses can override this method to handle the request in some other way, such as by substituting 0 or a sentinel value for nil and invoking setValue:forKey: again or setting the variable directly. The default implementation raises an NSInvalidArgumentException.
- (Object) setValue(value, forKey:key)
Sets the property of the receiver specified by a given key to a given value. If key identifies a to-one relationship, relate the object specified by value to the receiver, unrelating the previously related object if there was one. Given a collection object and a key that identifies a to-many relationship, relate the objects contained in the collection to the receiver, unrelating previously related objects if there were any. The search pattern that setValue:forKey: uses is described in Accessor Search Implementation Details in Key-Value Coding Programming Guide.In a reference-counted environment, if the instance variable is accessed directly, value is retained.
- (Object) setValue(value, forKeyPath:keyPath)
Sets the value for the property identified by a given key path to a given value. The default implementation of this method gets the destination object for each relationship using valueForKey:, and sends the final object a setValue:forKey: message.
- (Object) setValue(value, forUndefinedKey:key)
Invoked by setValue:forKey: when it finds no property for a given key. Subclasses can override this method to handle the request in some other way. The default implementation raises an NSUndefinedKeyException.
- (Object) setValuesForKeysWithDictionary(keyedValues)
Sets properties of the receiver with values from a given dictionary, using its keys to identify the properties. The default implementation invokes setValue:forKey: for each key-value pair, substituting nil for NSNull values in keyedValues.
- (Boolean) validateValue(ioValue, forKey:key, error:outError)
Returns a Boolean value that indicates whether the value specified by a given pointer is valid for the property identified by a given key.
The default implementation of this method searches the class of the
receiver for a validation method whose name matches the pattern
validate
- (Boolean) validateValue(ioValue, forKeyPath:inKeyPath, error:outError)
Returns a Boolean value that indicates whether the value specified by a given pointer is valid for a given key path relative to the receiver. The default implementation gets the destination object for each relationship using valueForKey: and returns the result of a validateValue:forKey:error: message to the final object.
- (Object) valueForKey(key)
Returns the value for the property identified by a given key.
The search pattern that valueForKey: uses to find the correct value to return is described in Accessor Search Implementation Details in Key-Value Coding Programming Guide.
- (Object) valueForKeyPath(keyPath)
Returns the value for the derived property identified by a given key path. The default implementation gets the destination object for each relationship using valueForKey: and returns the result of a valueForKey: message to the final object.
- (Object) valueForUndefinedKey(key)
Invoked by valueForKey: when it finds no property corresponding to a given key. Subclasses can override this method to return an alternate value for undefined keys. The default implementation raises an NSUndefinedKeyException.