• 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: 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


  • 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>)
 >Re: KVC and KVO for arrays (From: Jens Alfke <email@hidden>)
 >Re: KVC and KVO for arrays (From: Adam P Jenkins <email@hidden>)

  • Prev by Date: Re: KVC and KVO for arrays
  • Next by Date: Re: KVC and KVO for arrays
  • Previous by thread: Re: KVC and KVO for arrays
  • Next by thread: Re: KVC and KVO for arrays
  • Index(es):
    • Date
    • Thread