Re: key value observing and binding
Re: key value observing and binding
- Subject: Re: key value observing and binding
- From: mmalcolm crawford <email@hidden>
- Date: Fri, 2 Jan 2004 12:41:37 -0800
On Jan 2, 2004, at 3:16 AM, Francisco Tolmasky wrote:
Before I changed my class, I was able to use
setKeys:triggerChangeNotificationsForDependentKey:
to associate three keys with another. Yet, I then changed my class to
instead of having three instance variables to store these values in an
NSMutableDictionary [...] Yet, I would still like to make it so that
when I say [values
setObject: whatever forKey: @"one"]; the other key be marked as well.
Currently I do so like this:
- (void)setObject:(NSString *)anObject forKey:(NSString *)aKey
{
BOOL shouldNotify= [@"one" isEqual: aKey];
if(shouldNotify) [self willChangeValueForKey: @"two"];
[properties setObject: aValue forKey: aKey];
if(shouldNotify) [self didChangeValueForKey: @"two"];
}
There shouldn't be any need to do this.
I would suggest creating accessor methods for each of your attributes,
which update the value in the internal dictionary as appropriate. You
can then use setKeys:triggerChangeNotificationsForDependentKey: just as
you did before. See:
<
http://homepage.mac.com/mmalc/CocoaExamples/
DictionaryDependencies.zip>
for an example.
mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.