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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:46:06+00:00 2026-05-16T21:46:06+00:00

I have a custom NSManagedObject subclass, say, Person . I also have a UIView

  • 0

I have a custom NSManagedObject subclass, say, Person. I also have a UIView registered with -addObserver:forKeyPath:options:context: to observe various properties of a Person, some of which are persistent like “name” and others are just dumb KVO-compliant accessors unrelated to Core Data, like “drinking”.

@interface Person : NSManagedObject
{
    BOOL drinking;
}
@property (nonatomic, retain) NSString* name;
@property (nonatomic, readonly) BOOL drinking;
@end

@implementation Person
@dynamic name;
...
- (void) getDrunk {
    [self willChangeValueForKey: @"drinking"];
    drinking = YES;
    [self didChangeValueForKey: @"drinking"];
}
...
@end

Everything works. Whenever I send -getDrunk or set the name property, the view does get notified. I’m a happy man except when I read NSManagedObject docs which state:

+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key

Fact 1. YES if the receiver provides automatic support for key-value observing change notifications for key, otherwise NO.

Fact 2. The default implementation for NSManagedObject returns NO for modeled properties, and YES for unmodeled properties.

Now I’m trying hard to parse the above two facts from the docs. Checking Fact 2 is easy and class Person indeed returns NO for @”name” and YES for @”drinking”. But then, how does the view get notified when the name changes? KVO docs clearly say,

Using automatic observer notifications, it is not necessary to bracket changes to a property with invocations of willChangeValueForKey: and didChangeValueForKey: when mutating properties via key-value coding and key-value coding compliant methods.

So, if Person returns NO from +automaticallyNotifiesObserversForKey: for @”name”, it would seem that I have to manually wrap the name setter in will/didChangeValueForKey: for KVO to work. However, KVO works just fine. What am I missing? What’s the point in NSManagedObject‘s overriding +automaticallyNotifiesObserversForKey: and documenting it if does not seem to change standard KVO behaviour?

Please, help me regain my sanity.

  • 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-16T21:46:07+00:00Added an answer on May 16, 2026 at 9:46 pm

    Well, NSManagedObject does provide an implementation for the name property (as well as the - name and - setName: methods). I would assume that the implementations provided by Core Data do include calls to willChangeValueForKey: and didChangeValueForKey:.

    So, although the KVO is “automatic” in the sense that you didn’t have to do anything to make it work, I would imagine that it is not automatic in the sense that willChangeValueForKey: and didChangeValueForKey: are being called by the methods in NSManagedObject that provide the dynamic property implementations.

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

Sidebar

Related Questions

No related questions found

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.