• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
key value observing and binding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

key value observing and binding


  • Subject: key value observing and binding
  • From: Francisco Tolmasky <email@hidden>
  • Date: Fri, 2 Jan 2004 03:16:48 -0800

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, as so:

before:

NSString *one, *two, *three;

after:

NSMutableDictionary *values;

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"];
}

Is this an appropriate course of action, or a hack? I could also just
have it be that whenever the dictionary is changed the other key be
marked as well, but that would be inefficient. Is there a way around
this?


Thanks in advance,

Francisco Tolmasky
email@hidden
http://users.adelphia.net/~ftolmasky
_______________________________________________
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.

  • Follow-Ups:
    • Re: key value observing and binding
      • From: mmalcolm crawford <email@hidden>
  • Prev by Date: Re: Localization question
  • Next by Date: Re: How can we get notified when the user presses shift or apple keys etc.
  • Previous by thread: Re: Code optimization
  • Next by thread: Re: key value observing and binding
  • Index(es):
    • Date
    • Thread