• 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: KVC and KVO for arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVC and KVO for arrays


  • Subject: Re: KVC and KVO for arrays
  • From: Jens Alfke <email@hidden>
  • Date: Wed, 13 Feb 2008 09:08:38 -0800


On 13 Feb '08, at 8:51 AM, Adam P Jenkins wrote:

@implementation Palette
- (NSMutableArray*)kvoColors
{
 return [self mutableArrayValueForKey:@"colors"];
}
@end

Now, I can write
[[palette kvoColors] addObject:[NSColor whiteColor]];
and observers of palette will be duly notified.

This has always confused me, and I never got it to work right when I tried this technique. The weird part is that you have two KV properties for the same array, with different semantics. Your trick of declaring a "colors" ivar but no accessor methods looks like it helps, but one thing still worries me:


If I made that addObject call, as in your example, what KVO notifications does the Palette send? Is it the "kvoColors" or "colors" property that's notified as being changed?

I'm afraid that it would be the latter, which makes me somewhat afraid to use this technique, since I'd be too likely to get mixed up and register for notifications of "kvoColors" instead of "colors", and then spend hours trying to figure out why my listener doesn't get called...

—Jens_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: KVC and KVO for arrays
      • From: Adam P Jenkins <email@hidden>
References: 
 >KVC and KVO for arrays (From: Hans van der Meer <email@hidden>)
 >Re: KVC and KVO for arrays (From: Adam P Jenkins <email@hidden>)
 >Re: KVC and KVO for arrays (From: mmalc crawford <email@hidden>)
 >Re: KVC and KVO for arrays (From: Adam P Jenkins <email@hidden>)
 >Re: KVC and KVO for arrays (From: mmalc crawford <email@hidden>)
 >Re: KVC and KVO for arrays (From: Adam P Jenkins <email@hidden>)

  • Prev by Date: Re: ICal Alarm View
  • Next by Date: Re: SScrypto framework
  • Previous by thread: Re: KVC and KVO for arrays
  • Next by thread: Re: KVC and KVO for arrays
  • Index(es):
    • Date
    • Thread