views:

13

answers:

0

Hi,

I'm trying to use KVO to observe a mutable array : How can i use NSKeyValueObservingOptionNew and NSKeyValueObservingOptionOld to get the objects that have been inserted or removed ?

Here is what i tried :

in the viewDidLoad method :

[self addObserver:self
     forKeyPath:@"recipeList"
     options:NSKeyValueObservingOptionNew |
  NSKeyValueObservingOptionOld
     context:NULL];

in the observeValueForKeyPath method :

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context
{
 Recipe *newRecipe = [change valueForKey:NSKeyValueChangeNewKey];
 Recipe *oldRecipe = [change valueForKey:NSKeyValueChangeOldKey];
}

i get either EXC_BAD_ACCESS or inconsistent values in newRecipe and oldRecipe...

Can anybody help ? Thanks, vincent.