NSKeyValueObservingOptionOld
Indicates that the change dictionary should contain the old attribute value, if applicable.
What does it mean old attribute value?
The observer is notified when an observed key path changes it's value. The ´change` dictionary contains information related to how the observed key path has changed. This dictionary is only filled with the values according to the options that you provide when setting
NSKeyValueObservingOptionNew
- Specifies that you want to have access to the new value that the key path changed into. NSKeyValueObservingOptionOld
- Specifies that you want to have access to the old value that the key path changed from.If specified to be sent these old and/or new values are accessible from the change
dictionary using these keys:
NSKeyValueChangeNewKey
- To access the new value.NSKeyValueChangeOldKey
- To access the old/previous value.You can do something like:
[self addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
and pick up the values via:
CGSize newSize = [[change objectForKey:@"new"] CGSizeValue];
CGSize oldSize = [[change objectForKey:@"old"] CGSizeValue];
It means the dictionary that is an argument of observeValueForKeyPath:ofObject:change:context:
contains a key-value pair that tells you the old value of the observed property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With