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 15:33:41 -0800
On 13 Feb '08, 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.
Yeah, but then clients of your class have to access your property with
really ugly calls like
NSMutableArray *attendees = [party
mutableArrayValueForKey:@"attendees"];
This is really bad form, IMHO, because it breaks both object
encapsulation and compile-time method checking:
(1) There's nothing in the Party class that indicates "attendees" is
public. I could use the same technique to access any private instance
variable of a class, with neither compiler nor runtime warnings. The
"valueForKey" family of messages remind me of the old PEEK and POKE in
BASIC.
(2) If I misspell the key as "atendees", I won't get any compile-time
warning, just an exception at runtime.
(3) If the instance variable 'party' is by mistake typed as, say
Person* instead of Party*, I won't get a compile-time warning about
Person not having an "attendees" property.
(4) This is also 26 more characters to type, and much harder to read,
than "[party attendees]".
To some degree this is a matter of taste, but if I didn't care about
type-checking or data encapsulation, I'd be coding in Python
instead :) (and save a lot more than 26 characters; Python is hella
compact compared to Obj-C.)
—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