Lets say I have an NSArrayController which contains items each with netCost and netProfit properties and I want to create a Total Percent Profit label (containing the sum of the profits divided by the sum of the costs).
In the controller class with a reference to the array controller I've attempted to do this as follows:
+ (NSSet *)keyPathsForValuesAffectingTotalPercentProfit {
return [NSSet setWithObjects:
@"[email protected]",
@"[email protected]",
nil];
}
- (NSDecimalNumber *)totalPercentProfit {
NSDecimalNumber *totalProfit = [self valueForKeyPath:@"[email protected]"];
NSDecimalNumber *totalCost = [self valueForKeyPath:@"[email protected]"];
if (!([totalCost compare:[NSDecimalNumber zero]] == NSOrderedSame)) {
return [totalProfit decimalNumberByDividingBy:totalCost];
} else {
return nil;
}
}
Yet the label bound to this totalPercentProfit property does not get refreshed when the dependent key paths are changed.
Can anybody point me in the right direction for fixing this?