• 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
Bindings and Core Data question.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bindings and Core Data question.


  • Subject: Bindings and Core Data question.
  • From: Carlos Rivera <email@hidden>
  • Date: Fri, 7 Oct 2005 20:47:55 -0400

I have two entities specified in XCode{A, B}.  A has a 1 to 1
relationship with B, while B has 1 to many.  Now B(totalDistance) has
a property which is dependent on the sum of all the properties in each
A(distance).  Incidentally the Core Data Programming Guide: Core Data
FAQ section of the documentation has a  section which describes my
problem with a solution.  So I went ahead and implemented the
solution.  I added the method the following methods to B

- (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
{
    NSNumber *totalDistance = [self valueForKeyPath:@"email@hiddennce"];
    [self setTotalDistance: [totalDistance floatValue]];
}

Now in the A entity I have the following:

- (void)setB:(NSManagedObject *)value
{
    [self willChangeValueForKey: @"b"];
    [self setPrimitiveValue: value
                     forKey: @"b"];
    [self didChangeValueForKey: @"b"];


    [self addObserver:[self b]
           forKeyPath:@"distance"
              options:(NSKeyValueObservingOptionNew)
              context:NULL];

}


So everything compiles just fine but when I run and I change the
distance in A 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

  • Prev by Date: Re: Dealing with non-standard character sets...
  • Next by Date: Re: CoreData - sqlite - statement is still active
  • Previous by thread: Re: NSSliderCell Drawing Issue
  • Next by thread: Re: Bindings and Core Data question.
  • Index(es):
    • Date
    • Thread