Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6002585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:59:58+00:00 2026-05-23T00:59:58+00:00

I have a Core Data entity, bid, which has a relationship to many items,

  • 0

I have a Core Data entity, “bid”, which has a relationship to many “items”, called “itemLink”.

in IB, I have a text field bound to “total”, and that almost works.

In “bid.m” I have:

- (NSDecimalNumber *)total
{
    return [self valueForKeyPath:@"itemLink.@sum.price"];
}

I also have:

+ (NSSet *)keyPathsForValuesAffectingTotal { 
    return [NSSet setWithObjects:@"itemLink", nil]; 

}

When adding or deleting an item, “total” updates as expected. But if you change an “item” within the set of itemLink, the total is not getting refreshed. How do you get KVO to see when a related object in the linked NSSet has changed?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:59:59+00:00Added an answer on May 23, 2026 at 12:59 am

    It looks your problem is to do with the fact that keyPathsForValuesAffectingTotal only mentions the keyPath “itemLink”.

    Since that’s the path of a to-many relationship, you’re effectively telling your bid object to observe a set for changes. All that a set does is manage whether objects are members of it or not. So that explains why you get updates when items are added or removed from “itemLink”, but only that.

    You aren’t just interested in which items are members of the set though, you’re also interested in the (mutable) properties of those members — price in this case. So in addition to the above, you want each member of “itemLink” to notify all observers of the relevant bid object’s “total” key that “price” has changed whenever it changes.

    Unfortunately, it’s not as simple as adding “itemLink.price” as a dependent keypath in your Bid class, as KVO doesn’t allow you to observe ‘through’ to-many relationships.

    If you use a NSManagedObject subclass for instances of your Item entity, you could add this functionality manually. Override + automaticallyNotifiesObserversForKey: in your Item class to tell Cocoa you’re going to manage KVO notifications manually for the “price” key, then implement your own setPrice: method that sends the appropriate notification. Something like this:

    - (void)setPrice:(id)inPrice
    {
        // bid = inverse relationship of itemLink
        [[self valueForKey:@"bid"] willChangeValueForKey:@"total"];
        [self willChangeValueForKey:@"price"];
    
        [self setPrimitiveValue:inPrice forKey:@"price"];
    
        [self didChangeValueForKey:@"price"];
        [[self valueForKey:@"bid"] didChangeValueForKey:@"total"];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a core data entity which has an exclusive one to many relationship
I have an Core Data entity called Album; an album has a relationship to
I have a core data entity named Folder. Each Folder has a 1-to-many relationship
I've got a Core Data entity called Card which has a relationship info to
I have a Core Data entity which has a date attribute. I would like
I have a Core Data Entity which has three properties startDate, endDate and duration.
I have a Core Data entity called Item and it represents an item in
I have a Core Data entity which needs a gender property. I just need
I have an Core Data Entity with a number of attributes, which include amount(float),
Given the following Core Data Model: -> : to-one releationship ->>: to-many relationship Entity

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.