-observeValueForKeyPath:ofObject:change:context: only defined for abstract class. Runtime error
-observeValueForKeyPath:ofObject:change:context: only defined for abstract class. Runtime error
- Subject: -observeValueForKeyPath:ofObject:change:context: only defined for abstract class. Runtime error
- From: Carlos Rivera <email@hidden>
- Date: Tue, 11 Oct 2005 07:48:04 -0400
I have two entities specified in XCode{Trip, Car}. Trip has a 1 to 1
relationship with Car, while Car has 1 to many to Trip. Now Car has
a property(totalDistance) which is dependent on the sum of all the
properties in each
Trip(distance). Incidentally the Core Data Programming Guide: Core Data
FAQ section of the documentation has a section which describes a similar
problem with a solution. So I went ahead and implemented the
solution. I added the method the following methods to Car
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
if([keyPath isEqual:@"distance"])
{
NSLog(@"receiving notification that the distance changed");
[self updateTotalDistance];
}
}
- (void)updateTotalDistance
{
// Just in case the mainling list think it is a mail address I am
trying to use the trips."@"sum.distance
// to add all the "distance" attributes
NSNumber *totalDistance = [self valueForKeyPath:@"email@hiddennce"];
[self setTotalDistance: [totalDistance floatValue]];
}
Now in the Trip entity I have the following:
- (void)setCar:(NSManagedObject *)value
{
[self willChangeValueForKey: @"car"];
[self setPrimitiveValue: value
forKey: @"car"];
[self didChangeValueForKey: @"car"];
[self addObserver:[self car]
forKeyPath:@"distance"
options:(NSKeyValueObservingOptionNew)
context:NULL];
}
So everything compiles just fine but when I run and I change the
distance in Trip I get the following error:
-observeValueForKeyPath:ofObject:change:context: only defined for
abstract class. Define -[NSManagedObject
observeValueForKeyPath:ofObject:change:context:]!
Any ideas? I usually try as hard to find a solution before posting
but I have been stuck on this one for a couple of days.
Thank You.
_______________________________________________
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