One Quickie


Handling KVO with arrays (Bindings->General)
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 *) context
The NSKeyValueChangeKindKey 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 the NSKeyValueChangeOldKey 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.



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com