Should I set Core Data dependent key in the primary's setter?
Should I set Core Data dependent key in the primary's setter?
- Subject: Should I set Core Data dependent key in the primary's setter?
- From: Scott Ellsworth <email@hidden>
- Date: Wed, 17 Aug 2005 11:24:36 -0700
Hi, all.
I want the logPop attribute in my core data model to change whenever
the value of pop changes. The logPop attribute would not be in my
model at all, save that I now need to do queries on it. Formerly, I
used setKeys:triggerChangeNotificationsForDependentKey: to get the
proper notifications, sent, but formerly, I only had a computed
getter. Now, I need the actual value in the model, and I am not sure
where to set that computed value.
I could add a setValue:forKey:dependentProperty to the setter for the
primary property, but is this the best spot to do this?
Adding an observeValueForKeyPath seems like massive overkill - there
are tens to hundreds of thousands of these live.
Right now, I have:
+ (iniitalize) {
[self setKeys:[NSArray arrayWithObjects:@"pop",nil]
triggerChangeNotificationsForDependentKey:@"logPop"];
}
- (float) logPop{
float pop = [[self valueForKey:@"pop"] doubleValue];
return log10(pop);
}
but this will not let me use logPop in the model. Is this best done
via:
- (void)setPop:(float)value
{
[self willChangeValueForKey:@"pop"];
[self setPrimitiveValue: [NSNumber numberWithFloat: value]
forKey:@"pop"];
[self didChangeValueForKey:@"pop"];
[self setValue:log10(pop) forKey:@"logPop"];
}
or is there a better place to do the [self setValue:log10(pop)
forKey:@"logPop"] ?
Scott
_______________________________________________
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