Re: NSArray KVC proxy
Re: NSArray KVC proxy
- Subject: Re: NSArray KVC proxy
- From: Quincey Morris <email@hidden>
- Date: Sun, 25 Jan 2009 16:59:05 -0800
On Jan 25, 2009, at 15:54, Jeff Johnson wrote:
Ok, I understand. The question is, other than saving a few
characters, how is calling xxxx more convenient than calling
valueForKey:@"xxxx"?
It makes quite a difference to readability, I think. Also, Refactor...
works on property names but not on key strings, and that's fairly
important to me. Also, the getter can cache the proxy, while (I
assume) valueForKey: creates a new one each time it's called.
If the property is mutable, then you're going to have to call
mutableArrayValueForKey:@"xxxx" anyway, right?
Yes. I thought I found a way of returning that conditionally from a
single getter, but I think I was just mistaken. So, mutable access
needs a different name, e.g. "mutableXxxx". (IAC, the method's return
type really ought to be different -- NSMutableArray instead of NSArray.)
If you're just dealing with a read-only property, I suppose that one
option would be to give the property and getter a different name
than the key. This could be justified in the sense that the property
is public but the implementation via KVC is a private implementation
detail. Then it would be safe to call valueForKey: in your getter.
Yes. That's a possibility ("immutableXxxx"). The drawback is that it
leaves a big hole. Part of what I'm doing is laying down coding
patterns for others to follow when implementing classes, and, though a
rule like "Don't ever write a getter for an array property" is easy to
remember, it's even easier to forget.
_______________________________________________
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