• 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
Re: key value observing and binding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >key value observing and binding (From: Francisco Tolmasky <email@hidden>)

  • Prev by Date: Re: [OT] Encryption
  • Next by Date: Re: Localization question
  • Previous by thread: key value observing and binding
  • Next by thread: Strange crash log
  • Index(es):
    • Date
    • Thread