• 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
-observeValueForKeyPath:ofObject:change:context: only defined for abstract class. Runtime error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

-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

  • Follow-Ups:
    • Re: -observeValueForKeyPath:ofObject:change:context: only defined for abstract class. Runtime error
      • From: mmalcolm crawford <email@hidden>
    • Re: -observeValueForKeyPath:ofObject:change:context: only defined for abstract class. Runtime error
      • From: Jonathon Mah <email@hidden>
  • Prev by Date: Re: Am I using NSConditionLock correctly?
  • Next by Date: Send action on end editing
  • Previous by thread: Re: Difference between dvd and dmg
  • Next by thread: Re: -observeValueForKeyPath:ofObject:change:context: only defined for abstract class. Runtime error
  • Index(es):
    • Date
    • Thread