Can an object observe itself?
Can an object observe itself?
- Subject: Can an object observe itself?
- From: Stuart Malin <email@hidden>
- Date: Sat, 7 Mar 2009 10:31:01 -1000
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:
- (id) init {
self = [super init];
if (self != nil) {
mRealName = nil;
mUsername = nil;
mPassword = nil;
mFrequency = 15;
[self addObserver:self
forKeyPath:@"password"
options:NSKeyValueObservingOptionOld
context:NULL];
}
return self;
}
Should this work, and my problem is elsewhere?
To further isolate the problem, I made an explicit call to one of the -
set<Key> methods of one of the model objects (i.e., bypassing the
array controller). Still, I my observer was not triggered.
_______________________________________________
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