I am trying to gain a working understanding of KVC. I have made a small app that has a class Party which has a property "attendees" that holds Person objects. The attendees property is KVC compliant for a mutable array (it has index accessors). In another part of my app, I want to find the Nth attendee. My first approach to doing so was to code: Person *person = [[party mutableArrayValueForKey:@"attendees"] objectAtIndex:index]; This does work, and, as I best understand, it complies with the KVC protocol. But I do believe this approach generates a proxy mutable array, which seems inefficient to me. As the underlying Party class is KVC compliant for the attendees property, I substituted the above with:
        Person *person = [party objectInAttendeesAtIndex:index];
This does work. But I sense I may be breaking some sort of "encapsulation" regarding the workings of KVC by using the accessors that support it.
The compiler issued a warning that "Party" may not respond to - 
objectInAttendeesAtIndex: because I hadn't included the index  
accessors in the class's header file... Which I could do.... But then  
wonder even more if I am exposing something that I shouldn't.   
Question: is it acceptable (perhaps even desirable) to expose the  
index accessors of a class via its interface declaration (header file)?
Also: I could add a method to my Party class to provide such access  
in a way that seems more semantically direct, to wit:  -personAtIndex:
Would providing such a method be preferred to having code elsewhere  
in the app use the Party class's KVC index accessor(s)?
(It does seem quite redundant)

~~~

Separately, I have an accessor -attendees: of the Party class, which is currently implemented as:
- (NSArray*) attendees
{
return [NSArray arrayWithArray:attendees]; // "attendees" is an NSMutableArray, and is an ivar
}

I intentionally do not return the underlying mutable array, because I don't want other code accessing the content without going through the accessors.
Is my implementation reasonable? Or are there preferable ways to do  
this (such as to return a copy of the mutable array)?

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to