Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chiklit

macrumors newbie
Original poster
Oct 15, 2007
2
0
Hi everyone. I'm working with a Core Data app where I have an entity called "Candy" and it has 4 properties: brandName, unitPrice, quantity, and totalValue.

totalValue is derived from subclassing NSManagedObject and calculating the value in code, the others are defined in the .xcdatamodel.

Code:
@implementation CandyEntity

- (NSNumber *)totalValue
{
	int quantity;
	float unitPrice;
	float totalPrice;
	
	[self willAccessValueForKey:@"quantity"];
	[self willAccessValueForKey:@"unitPrice"];
	
	quantity = [[self primitiveValueForKey:@"quantity"] intValue];
	unitPrice = [[self primitiveValueForKey:@"unitPrice"] floatValue];
	
	[self didAccessValueForKey:@"quantity"];
	[self didAccessValueForKey:@"unitPrice"];
	
	totalPrice = quantity * unitPrice;
	
	NSNumber *total = [NSNumber numberWithFloat:totalPrice];
	return total;
}

What I'm trying to do is take all of the values from the totalValue column, sum them, and then put that sum into an NSTextField. I've tried doing this by binding the textfield value to "Candy.arrangedObjects.@sum.totalValue" but that seems to always return 0, and I imagine it's because it's a code-derived value instead of actually existing in the array, since doing "Candy.arrangedObjects.@sum.unitPrice" works as expected.

Any ideas how I can get around this? Do I need to load the values from totalValue into the array as well?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.