Re: KVC and KVO for arrays
Re: KVC and KVO for arrays
- Subject: Re: KVC and KVO for arrays
- From: mmalc crawford <email@hidden>
- Date: Wed, 13 Feb 2008 13:30:05 -0800
On Feb 13, 2008, at 11:24 AM, Adam P Jenkins wrote:
The kvoColors method is not necessary, and you can leave it out if
you think it confuses things. I just added it for illustrative
purposes. By default, simply adding an instance variable is enough
to create a KVC and KVO compliant property, unless a subclass has
overridden accessInstanceVariablesDirectly to return FALSE. Here
is a complete and compilable program which demonstrates a Party
class with an attendees array property, and demonstrates an observer
receiving events about the array being modified in place, all
without writing any indexed accessors.
#import <Foundation/Foundation.h>
@interface Party : NSObject
{
// just adding this instance variable is enough to create a KVC and
KVO compliant
// attendees property
NSMutableArray *attendees;
}
- (void)printAttendeesAddress;
@end
@implementation Party
- (id)init {
[super init];
attendees = [NSMutableArray array];
return self;
}
- (void)printAttendeesAddress {
NSLog(@"Attendees array is at address %p", attendees);
}
@end
It's not clear why you're making things more complicated than necessary.
Just uses indexed accessors.
The above will not work unless you're using garbage collection...
mmalc
_______________________________________________
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