NSKeyValueCoding Protocol Reference
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.
The basic methods for accessing an object’s values are setValue:forKey:
, which sets the value for the property identified by the specified key, and 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).
Getting Values
-
– valueForKey:
-
– valueForKeyPath:
-
– dictionaryWithValuesForKeys:
-
– valueForUndefinedKey:
-
– mutableArrayValueForKey:
-
– mutableArrayValueForKeyPath:
-
– mutableSetValueForKey:
-
– mutableSetValueForKeyPath:
-
– mutableOrderedSetValueForKey:
-
– mutableOrderedSetValueForKeyPath:
Setting Values
-
– setValue:forKeyPath:
-
– setValuesForKeysWithDictionary:
-
– setNilValueForKey:
-
– setValue:forKey:
-
– setValue:forUndefinedKey:
Changing Default Behavior
Validation
NSKeyValueObserving Protocol Reference
he NSKeyValueObserving
(KVO) informal protocol defines a mechanism that allows objects to be notified of changes to the specified properties of other objects.
You can observe any object properties including simple attributes, to-one relationships, and to-many relationships. Observers of to-many relationships are informed of the type of change made — as well as which objects are involved in the change.
NSObject
provides an implementation of the NSKeyValueObserving
protocol that provides an automatic observing capability for all objects. You can further refine notifications by disabling automatic observer notifications and implementing manual notifications using the methods in this protocol.
Change Notification
Registering for Observation
-
– addObserver:forKeyPath:options:context:
-
– removeObserver:forKeyPath:
-
– removeObserver:forKeyPath:context:
Notifying Observers of Changes
-
– willChangeValueForKey:
-
– didChangeValueForKey:
-
– willChange:valuesAtIndexes:forKey:
-
– didChange:valuesAtIndexes:forKey:
-
– willChangeValueForKey:withSetMutation:usingObjects:
-
– didChangeValueForKey:withSetMutation:usingObjects:
Observing Customization
-
+ automaticallyNotifiesObserversForKey:
-
+ keyPathsForValuesAffectingValueForKey:
-
– setObservationInfo:
-
– observationInfo
kvc 就是一种通过字符串去间接操作对象属性的机制, |