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


  • 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: NSTokenField bug in 10.5.2?
  • Next by Date: Re: Setting alignment of NSTextView programmatically
  • Previous by thread: Re: KVC and KVO for arrays
  • Next by thread: Re: KVC and KVO for arrays
  • Index(es):
    • Date
    • Thread