• 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: Can an object observe itself?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can an object observe itself?


  • Subject: Re: Can an object observe itself?
  • From: Stuart Malin <email@hidden>
  • Date: Sat, 7 Mar 2009 11:25:01 -1000


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@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: 
 >Can an object observe itself? (From: Stuart Malin <email@hidden>)
 >Re: Can an object observe itself? (From: Keary Suska <email@hidden>)

  • Prev by Date: Trying to understand the cause of a "message sent to deallocated instance" error
  • Next by Date: Re: Trying to understand the cause of a "message sent to deallocated instance" error
  • Previous by thread: Re: Can an object observe itself?
  • Next by thread: Re: Can an object observe itself?
  • Index(es):
    • Date
    • Thread