Re: KVC and KVO for arrays
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