• 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 09:28:11 -0500

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.
>
> One alternative approach is to use *two* property names: <privateKey> and <publicKey>.
>
> You can then have <publicKey>'s getter return '[self valueForKey: @"privateKey"]'. That solves the infinitely-recursing-getter problem, but still returns an immutable observable proxy.

On Jul 11, 2012, at 1:55 AM, Quincey Morris wrote:

> Ugh, that's not right. You have to generate the <publicKey> KVO notifications manually in order to make the proxy properly observable. That means calling suitable will/didChange… methods in suitable places.

You can use +keyPathsForValuesAffecting<PublicKey> to make the public property emit KVO change notifications whenever the private property changes.  However, I doubt that emits appropriate *array-specific* KVO change notifications for the public property – i.e. those whose change kind is NSKeyValueChangeInsertion, NSKeyValueChangeRemoval, or NSKeyValueChangeReplacement.  Rather it will probably just emit whole-property-replaced (NSKeyValueChangeSetting) notifications.

(By the way, you're using the term "proxy" in a manner which I find confusing.)


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.  I couldn't tell if that's what you meant by:

> A second alternative approach is write your own mutable and immutable array proxies (subclasses of NSArray) instead of using the ones provided by KVC. It isn't terribly hard.

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


  • Follow-Ups:
    • Re: Limited-access, KVO-compliant mutable array?
      • From: Quincey Morris <email@hidden>
    • Re: Limited-access, KVO-compliant mutable array?
      • From: Ken Thomases <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>)

  • Prev by Date: Re: How to implement an object whose properties are really dictionary entries.
  • 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