Resolved Key-value observing: get old value

Discussion in 'iOS Programming' started by moonman239, Jul 14, 2014.

  1. moonman239 macrumors 68000

    Mar 27, 2009
    I set one of my view controllers to observe a key. I wanted the view controller to call a method if the key's was changed, and pass along the old value.

    Here is what I learned (thanks to Mike Nachbaur for helping me):

    First, you'll need to ensure the NSKeyValueObservingOptionOld option is listed in the options argument of the addObserver method of the object whose key you want the observer to observe.

    Next, in the observer's observeValue method, you can get the old value by getting the value of a key that is in the change directory. This key is denoted by the constant named "NSKeyValueChangeOldKey."
  2. JohnsonK macrumors regular

    Mar 6, 2014
  3. moonman239 thread starter macrumors 68000

    Mar 27, 2009
    I don't have one. I just posted a solution that I found.

Share This Page