recursing bindings?
recursing bindings?
- Subject: recursing bindings?
- From: Joshua Scott Emmons <email@hidden>
- Date: Thu, 16 Jun 2005 15:59:31 -0400
Based on examples, I've written binding into a custom class of mine.
This involves implementing bind... observeValueForKeyPath... and
setValue... as follows:
-(void)bind:(NSString *)binding
toObject:(id)observableObject
withKeyPath:(NSString *)keyPath
options:(NSDictionary *)options{
observedObjectForIndex = [observableObject retain];
observedKeyPathForIndex = [keyPath copy];
[observableObject addObserver:self forKeyPath:keyPath options:nil
context:(void *)@"thing"];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context{
id myValue = [object valueForKeyPath:keyPath];
[self setValue:myValue];
}
}
-(void)setValue:(NSString *)aValue{
[value release];
value = [aValue copy];
if(nil != observedObjectForIndex){
[observedObjectForIndex setValue:aValue
forKeyPath:observedKeyPathForIndex];
}
}
The problem is, if I setValue..., this sends the value to the
observable object. This, in turn, causes the observable object to
message me with an observeValueForKeyPath... which causes me to
setValue... which sets the observable object which causes it to
message me with an obeserveValueForKeyPath... etc. etc.
How do I update the observable object I'm bound to without causing it
to immediately send me an observeValueForKeyPath... with the value I
just sent it?
Cheers,
-Joshua Emmons
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden