Search code examples
objective-ccocoakey-value-observing

Retrieving the information in the `change` dictionary from KVO


The method

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
}

has a parameter change which is a dictionary that contains information about the nature of the value change, how would I find out what was in this dictionary?


Solution

  • Here's a list of the keys used by the change dictionary.

    An extract:

    Keys used by the change dictionary

    These constants are used as keys in the change dictionary passed to observeValueForKeyPath:ofObject:change:context:.

    NSString *const NSKeyValueChangeKindKey;
    NSString *const NSKeyValueChangeNewKey;
    NSString *const NSKeyValueChangeOldKey;
    NSString *const NSKeyValueChangeIndexesKey;
    NSString *const NSKeyValueChangeNotificationIsPriorKey;