Re: Observing Collections
Re: Observing Collections
- Subject: Re: Observing Collections
- From: Hamish Allan <email@hidden>
- Date: Thu, 5 Jan 2006 07:53:44 +0000
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:
This email sent to email@hidden