On Mar 7, 2009, at 11:18 AM, Keary Suska wrote:

On Mar 7, 2009, at 1:31 PM, Stuart Malin wrote:

I have a model class with multiple properties. I need to know in a variety of places when certain of these change. Presently, the model objects can be changed by an inspector that has bindings to the model instances, which are managed as a collection by an NSArrayController. So... I tried adding code to the model object to observe itself (on a key that is a dependent key set up with +setKeys:triggerChangeNitificationsForDependentKeys). I was then going to have that observer issue a notification. However, the model's -observeValueForKeyPath:ofObject:change:context: method isn't getting called when I make changes. Thinking the problem was with the dependent key, I changed to observe a specific key. That doesn't work either. So I am wondering if an object can observe itself. I add the observer in the model object's -init method, after invoking -init on the superclass:


The main issue is that you have to remove observation before deallocating. Otherwise an exception will be raised (Leopard) or you will crash (Tiger and earlier).

Yes, I do remove the observer in -dealloc.

My problem was that I also created instances via NSCoding protocol methods (-initWithCoder) and had not there set the observer in place, and the source of my model objects was via that.

Thanks for your help and interest!


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to