When you insert or remove objects in a KVO compliant manner, your observer is informed of the specifics of the change via the change dictionary:- (void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object change: (NSDictionary *) change context: (void *) contextTheNSKeyValueChangeKindKey
key in the dictionary tells you if the change was an insertion (NSKeyValueMinusSetMutation
) or a deletion (NSKeyValueIntersectSetMutation
)If it is an insertion, the
NSKeyValueChangeIndexesKey
is an index set that contains the index of the inserted object. You can query the collection for the object at that index to get the new object.if it a deletion, the
NSKeyValueChangeIndexesKey
tells you the index where the object was deleted from, and theNSKeyValueChangeOldKey
contains an NSArray of objects which were removed, in case you want to hang on to it, or use it to clean out some of your data structures.