• 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: Limited-access, KVO-compliant mutable array?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Limited-access, KVO-compliant mutable array? (From: Rick Mann <email@hidden>)
 >Re: Limited-access, KVO-compliant mutable array? (From: Quincey Morris <email@hidden>)
 >Re: Limited-access, KVO-compliant mutable array? (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Instance not responding to selector
  • Next by Date: Re: Save photo taken by UIImagePickerController
  • Previous by thread: Re: Limited-access, KVO-compliant mutable array?
  • Next by thread: Re: Limited-access, KVO-compliant mutable array?
  • Index(es):
    • Date
    • Thread