• 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: Question about model observers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about model observers


  • Subject: Re: Question about model observers
  • From: Ken Thomases <email@hidden>
  • Date: Wed, 12 May 2010 13:04:02 -0500

On May 12, 2010, at 11:44 AM, Quincey Morris wrote:

> *All* collections emit KVO notifications when their contents change, in the sense of objects entering or leaving the collection. Add, remove and replace for arrays, add and remove for sets, set and remove for dictionaries.

Arrays and sets may (probably; I haven't checked) emit change notifications for their "count" and "description" properties when elements are added or removed.  But they don't emit change notifications regarding the specific elements that they contain, which is what I think Keary was getting at.  In particular, they don't emit a change notification of kind NSKeyValueChangeInsertion, NSKeyValueChangeRemoval, or NSKeyValueChangeReplacement.

> Perhaps the difference between dictionaries and other collections is this: There is no way to *name*, via a KVC keypath, the objects in an array or set. There *is* a way to name via keypath the objects in a dictionary.

It's deeper than that.  It's not just a matter of naming.  It may indeed be too early in the morning for you, since I'm sure you know the following: KVO reports changes to a _property_ of an _object_.  Both pieces, object and property, are part of the change notification.  Elements of an array or set are not properties of the collection; they are merely elements.

What invocation(s) of -observeValueForKeyPath:ofObject:change:context: would you expect to flow from the addition or removal of an element to an array or set?  What would the arguments be?



> *No* collections (AFAIK) emit KVO notifications when their contained objects change (that is, when a property of a contained object changes). They can't, in general, because there's no general definition of what it means for an object to "change". (Some properties might change but not be regarded as the object changing; some internal state might change with no change in properties.)


Agreed, and I don't think anybody was suggesting that.

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: Question about model observers
      • From: Quincey Morris <email@hidden>
References: 
 >Question about model observers (From: Eric Giguere <email@hidden>)
 >Re: Question about model observers (From: Keary Suska <email@hidden>)
 >Re: Question about model observers (From: Eric Giguere <email@hidden>)
 >Re: Question about model observers (From: Keary Suska <email@hidden>)
 >Re: Question about model observers (From: Ken Thomases <email@hidden>)
 >Re: Question about model observers (From: Keary Suska <email@hidden>)
 >Re: Question about model observers (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Handling bindings of an NSControl which forward everything to an NSCell?
  • Next by Date: loaded object: (0x0)
  • Previous by thread: Re: Question about model observers
  • Next by thread: Re: Question about model observers
  • Index(es):
    • Date
    • Thread