3

How can I get a notification when an object has been added/removed through an NSArrayController ?

I tried something like

    [core addObserver:self forKeyPath:@"arrangedObjects" options:0 context:nil];

I do get a notification of something has been added or remove but I don't know which object and I don't know what has been done (removing or adding).

The change dictionary of observeValueForKeyPath:ofObject:change:context: doesn't return any useful information.

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134

1 Answers1

1

I would bind a NSMutableArray to the NSArrayController's contentArray and observe that.

@property (retain) NSMutableArray *array;

[self addObserver:self forKeyPath:@"array" options:NSKeyValueObservingOptionNew context:NULL];

To get the changed index, you can use

[(NSIndexSet *)[[change allValues] lastObject] lastIndex];
Oath Comrade
  • 283
  • 2
  • 9