• 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: KVO: Observing an aggregate property of a collection?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO: Observing an aggregate property of a collection?


  • Subject: Re: KVO: Observing an aggregate property of a collection?
  • From: Chris Suter <email@hidden>
  • Date: Fri, 11 Jul 2008 09:50:57 +1000


On 11/07/2008, at 7:46 AM, Jens Alfke wrote:

How do I set up key-value observing of an aggregate property over an array, like a sum?

Say I have a Bulb class with a boolean "lit" property. I have an NSArrayController with an array of Bulbs, being shown in a table view. To compute the number of lit bulbs I can do:
- (unsigned) litCount {
return [_bulbArrayController valueForKeyPath: @"email@hidden"];
}


Now if I want to display this count in my UI, I need to get notifications of when it changes. But what keypath do I observe? I've tried "email@hidden", and I don't get any exceptions, but the observer never triggers when I change the "lit" property of a bulb in the array.

I believe that should work without any problem so long as you're not adding or removing elements from the array using addObject, removeObject or any of the other primitives (you have to modify the array in a different way if you want that to work). If you're simply modifying the property of an existing element, I believe it should work. Can you post a test case?


--Chris

_______________________________________________

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: 
 >KVO: Observing an aggregate property of a collection? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Why can't I name a property `tag'?
  • Next by Date: Re: Best way to handle background i/o and notify main UI thread
  • Previous by thread: KVO: Observing an aggregate property of a collection?
  • Next by thread: NSOutlineView hiding a column while editing a row in another column
  • Index(es):
    • Date
    • Thread