Re: mutableArrayValueForKey: truth or dare
Re: mutableArrayValueForKey: truth or dare
- Subject: Re: mutableArrayValueForKey: truth or dare
- From: Charles Srstka <email@hidden>
- Date: Thu, 17 Jun 2010 20:41:45 -0500
On Jun 17, 2010, at 8:19 PM, Matt Neuburg wrote:
> On or about 6/17/10 5:56 PM, thus spake "Roland King" <email@hidden>:
>
>> if ... you just have a class variable called <key> or _<key> then the
>> whole array is not replaced, the method you call on NSMutableArrayValueForKey:
>> is passed through to that underlying variable which does what you might expect
>> and operates on the array variable directly.
>>
>> That's not such a rare case.
>
> In fact it is exactly the case I had in mind. :) That's really just what I
> wanted to hear. Someone asked "how do you think the proxy object works";
> that *is* how I was thinking it might work. Thx - m.
The problem with things like this is the way it destroys encapsulation. It absolutely gives me the willies the way KVO can be used to completely bypass encapsulation, allowing any object that wants to to read the contents of any instance variable — even ones that are declared @private — by using valueForKey:, and even to change these ivars (!!!) using -setValue:forKey:.
Yes, I am aware that you can override accessInstanceVariablesDirectly to return NO. However, the default is YES, which means that any instance variable for any object for which the developer didn’t think to override this method can be monkeyed with by any other code running anywhere! The scariest thing is that it could even be done accidentally, if someone uses a wrong key by mistake, which just happens to be the name of an instance variable!
Long story short, since my hope is that Apple eventually comes to their senses and changes this behavior, you’d be safest just implementing the accessor methods like you’re supposed to.
Charles_______________________________________________
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