Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Observing Collections




On Thu Jan 05 03:05:20 2006, mmalcolm crawford wrote:

<http://homepage.mac.com/mmalc/CocoaExamples/controllers.html>
See "Graphics Bindings".

Interesting comment in your code! Do you know if this is still the case?

/*
 Should be able to use
 NSArray *oldGraphics = [change objectForKey:NSKeyValueChangeOldKey];
 etc. but the dictionary doesn't contain old and new arrays...??
*/

Also I got the impression from the docs (http://developer.apple.com/ documentation/Cocoa/Reference/Foundation/ObjC_classic/Protocols/ NSKeyValueObserving.html#//apple_ref/doc/c_ref/ NSKeyValueChangeNewKey) that the NSKeyValueChange[Old|New]Keys would contain the deltas:

"For NSKeyValueChangeInsertion or NSKeyValueChangeReplacement, if NSKeyValueObservingOptionNew was specified when the observer was registered, the value for [NSKeyValueChangeNewKey] is an NSArray of the objects that have been inserted or replaced other objects, respectively.

For NSKeyValueChangeRemoval or NSKeyValueChangeReplacement, if NSKeyValueObservingOptionOld was specified when the observer was registered, the value [for NSKeyValueChangeOldKey] is an NSArray of the objects that have been removed or have been replaced by other objects, respectively."

i.e., they would be akin to onlyOld / onlyNew rather than oldGraphics / newGraphics in your code.

I should probably have included a more high-level description of the "NSMutableSetWithObservations" code I posted. It's intended to be an NSMutableSet which takes care of registering and de-registering observers for certain key paths of contained objects during the lifetime of their containment. I got the impression that Chad was looking for a generic solution -- my code does pretty much the same as yours but at the level of the collection. Having read your code, I would change mine to use a context:

a
> static void *CollectionContentsChangeContext = (void *)9102;

c
<            context:NULL];
---
>            context:CollectionContentsChangedContext];

c
<    if (object == self && [keyPath isEqualToString:@"self"])
---
>    if (context == CollectionContentsChangedContext)


Best wishes, Hamish

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Observing Collections (From: Hamish Allan <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.