Re: Limited-access, KVO-compliant mutable array?
Re: Limited-access, KVO-compliant mutable array?
- Subject: Re: Limited-access, KVO-compliant mutable array?
- From: Ken Thomases <email@hidden>
- Date: Wed, 11 Jul 2012 10:16:29 -0500
On Jul 11, 2012, at 9:28 AM, Ken Thomases wrote:
> On Jul 11, 2012, at 1:45 AM, Quincey Morris wrote:
>
>> **** There isn't AFAIK a really easy way to prevent clients that aren't supposed to mutate the property from just invoking 'mutableArrayValueForKey: @"<key>"' by themselves.
> Another approach is to just define a single property. Instead of implementing the KVC-compliant indexed accessor mutation methods, implement variants with a slightly non-conformant name (perhaps with a prefix of "private"). Then have those manually emit the proper KVO change notifications by invoking -will/didChange:valuesAtIndexes:forKey:. Use those private methods to mutate the property from within your own code.
Oh, and I forgot to say: always, *always* override +accessInstanceVariablesDirectly to return NO in all of your classes. KVC's direct instance variable access is an encapsulation-violating abomination.
Regards,
Ken
_______________________________________________
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