• 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: Observing NSArrayController's content, shouldn't it be simple ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Observing NSArrayController's content, shouldn't it be simple ?


  • Subject: Re: Observing NSArrayController's content, shouldn't it be simple ?
  • From: Yann Bizeul <email@hidden>
  • Date: Tue, 8 May 2007 09:55:50 +0200

Thanks for replying to both of you.

It makes perfect sense, that's what I thought when I see the change kind.
The question is : how to observe the array itself without going to the parent object's property ?
I think I cannot use arrangedObjects for the same reasons, "content" looked like the closer property that would represent my array, so if it is not, is there something else ?


Best regards,


Yann Bizeul - yann at tynsoe.org Cocoa Developer

Tynsoe Projects
BuddyPop - GeekTool - SSH Tunnel Manager - ...
http://projects.tynsoe.org/


Le 8 mai 07 à 08:37, Chris Hanson a écrit :

On May 7, 2007, at 1:06 AM, Yann Bizeul wrote:

What I want to do is quite simple, I just want to register as an observer for A's content, and get added/removed values.

So I do register like this :
[A addObserver:self forKeyPath:@"content" options: NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];


And I'm listening like this :

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id) object change:(NSDictionary *)change context:(void *)context
{
NSLog(@"%@",change);
}


But all I get each time I add an object is :
{kind = 1; new = <null>; old = <null>; }

While it may be a bug that you're not receiving the old/new values that you asked for in the change dictionary, you are still getting a correct notification for the change itself. An NSKeyValueChangeKindKey (kind) value of NSKeyValueChangeSetting (1) means that the property you're observing changed.


Note that what you set out to do -- and what is actually being done -- is observe A's "content" property. When the "content" property of A is changed to something else, you'll get the behavior you're seeing. (And, as I said above, you might also legitimately expect to receive the old and new values in the change dictionary.)

If what you really want to observe changes to the *value* of whatever A's "content" property is, then you should observe it directly. For example, if A's "content" property is an array or set, you can observe that array or set itself in order to be notified of its mutations.

This might work better as a diagram:

   A --> content --> something

You're looking at "content" and getting notified that it's (effectively) being set each time "something" changes. But what you seem to be really interested in are finer-grained changes to "something" so you should observe it instead.

  -- Chris



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: 
 >Observing NSArrayController's content, shouldn't it be simple ? (From: Yann Bizeul <email@hidden>)
 >Re: Observing NSArrayController's content, shouldn't it be simple ? (From: Chris Hanson <email@hidden>)

  • Prev by Date: SOLVED: Issues with Core Data, NSTreeController, and observedObject
  • Next by Date: Re: Does Core Data have a serious problem?
  • Previous by thread: Re: Observing NSArrayController's content, shouldn't it be simple ?
  • Next by thread: Core Data Entities in NSArray
  • Index(es):
    • Date
    • Thread