I would like to know the correct way to implement a non-stored value that is dependent on members of a collection.

I am setting up the object that holds the dependent value as an observer of the individual members of the collection like this:

[theFrameModule addObserver:self forKeyPath:kOverallWidth options:NSKeyValueObservingOptionNew context:NULL];

And I use the following to see when one of the items in the collection has changed:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:kOverallWidth]) {
                NSLog(@"got notification that overallwidth changed: %@", 
object);
    }
}


This works just fine. I get notified of the changes to the members of the collection.

But my question is this:

I want my dependent value to exist very simply as a method. I don't need or want it to be an ivar of its object. So something like this:

-(NSInteger)overallWidth;
{
        NSInteger overallWidthSubtotal = 0;
        for ( SLFrameModule * theModule in [self frameModules] )
        {
                overallWidthSubtotal += [theModule overallWidth];
        }
        
        return overallWidthSubtotal;
}

My problem is that when I use overallWidth in a binding, the value does not get updated. There is some "tickle" that is not occurring.

I have replaced my -overallWidth method above with an iVar, and that does work, but I would rather have it exist solely as the method above. Is there any way to put something in my - observeValueForKeyPath: method that will tell the KVO system that overallWidth would be a different value if checked?

Thank you
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to