Search code examples
iphonekey-value-observing

What is the difference between NSKeyValueObservingOptionNew and NSKeyValueObservingOptionOld?


NSKeyValueObservingOptionOld
    Indicates that the change dictionary should contain the old attribute value, if applicable.

What does it mean old attribute value?


Solution

  • 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.