Skip navigation.
 
mlGetting modified object in observeValueForKeyPath:ofObject:change:context: for non-simple key paths
FROM : Mike R. Manzano
DATE : Wed Nov 28 20:25:57 2007

Hi all,

I'd like to get notifications when a particular property of any object 
in a to-many relationship changes. Right now, I do that by observing 
the key path "arrangedObjects.serviceURL" on an NSArrayController. 
This does indeed notify me when any of the serviceURL properties 
change. However, I can't seem to figure out how to get the specific 
object in the array whose property was changed from the arguments 
passed in observeValueForKeyPath:...

I did manage to get the object by going directly to the 
NSArrayController and asking it for its selection, but it seems a bit 
hackish to do so (i.e., does Cocoa guaranteed that the selection will 
always be set correctly when observeValueForKeyPath:... is called?)

Is there a proper work-around pattern for this?

Another related question, what if I'm binding to an object that 
doesn't have a concept of selection? For example, if I wanted to bind 
to NSManagedContext's -registeredObjects (I actually haven't tried 
this yet, but will in a moment).

Thanks,

Mike

Related mailsAuthorDate
No related mails found.