• 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
Dependent values that are not iVars
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dependent values that are not iVars


  • Subject: Dependent values that are not iVars
  • From: Paul Bruneau <email@hidden>
  • Date: Fri, 18 Dec 2009 13:20:42 -0500

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 (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


  • Follow-Ups:
    • Re: Dependent values that are not iVars
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Detecting system protected folders.
  • Next by Date: Re: Detecting system protected folders.
  • Previous by thread: AppleGlot 3.4 not processing XIB files
  • Next by thread: Re: Dependent values that are not iVars
  • Index(es):
    • Date
    • Thread