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 7582211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:22:51+00:00 2026-05-30T18:22:51+00:00

This is a simplified example that should be enough for the question. @interface MyClass:

  • 0

This is a simplified example that should be enough for the question.

@interface MyClass: NSObject {
   Person *_owner;
}
   @property (strong) Person *owner;
   @property (readonly) BOOL hasSomething;
@end

@implementation
   // other code here like -init
   - (void)setOwner:(Person *)newOwner
   {
       [_owner removeObserver:self forKeyPath:@"stuff"];
       _owner = newOwner;
       [_owner addObserver:self forKeyPath:@"stuff" options:0 context:NULL];
   }
   - (Person*)owner
   {
       return _owner;
   }
   - (BOOL)hasSomething
   {
       return owner.stuff > 0;
   }
   - (void)observeValueForKeyPath:(NSString*)kp ofObject:(id)obj change:(NSDictionary*)ch context:(void*)c
   {
       if ([kp isEqualtToString:@"stuff"]) {
           [self willChangeValueForKey:@"hasSomething"];
           [self didChangeValueForKey:@"hasSomething"];
       }
   }
@end

In my example, anything bound to hasSomething is not properly notified of a change of value. What am I missing?

  • 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-30T18:22:53+00:00Added an answer on May 30, 2026 at 6:22 pm

    My workaround:
    I initially worked around the issue by binding straight to the value that I wanted to track. In the example given it would have looked like arrangedObjects.owner.stuff.

    My Solution:
    I later revisited the code and discovered that what I had was essentially correct. The idea was to encapsulate the inner working of a hierarchy of objects (which isn’t achieve if you bind the whole path like my workaround above). In the question, I simplified the problem to a hierarchy with two levels : MyClass -> Person. My code actually involves more levels and a to-many relationship. One of the elements in the hierarchy wasn’t properly observing its children.


    Denis suggested I take a look at -automaticallyNotifiesObserversForKey: and I did. From my understanding, you would want to have the method return NO in the event you want to send the notification manually within the setter method of the property. Otherwise, your notifications conflict with the automatic ones.

    - (void)setHasSomething:(BOOL)newVal
    {
        [self willChangeValueForKey:@"hasSomething"];
        // ...
        [self didChangeValueForKey:@"hasSomething"];
    }
    

    Since there’s no setter method for a readonly property, having it didn’t solve my problem.


    Lessons learned: 1) Observe your children properly; 2) Don’t over-simplify your problem when asking for help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a simplified example to illustrate the question: class A {}; class B
I have an HTML table that is similar to this simplified example: <table> <tbody>
This should be quite a simple problem, I've come across it enough that there
Just created an acc on SO to ask this :) Assuming this simplified example:
I've simplified this example as much as I can. I have a remote function:
I cannot find the solution for this problem, here is the simplified example: On
<h:commandLink id=#{id} value=#{value} action=#{actionBean.getAction} onclick=alert(this);/> In the previous simplified example, the 'this' keyword used
This example is simplified a bit, but in my ASP.NET web page in my
I need some help putting together this query in Django. I've simplified the example
The simplified example this; picture a Venn diagram made from two elements, A and

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.