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

  • Home
  • SEARCH
  • 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 3427482
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:50:30+00:00 2026-05-18T06:50:30+00:00

-setPrimitiveValue:forKey: won’t trigger KVO notifications. But in my brain, KVO only makes sense when

  • 0

-setPrimitiveValue:forKey: won’t trigger KVO notifications. But in my brain, KVO only makes sense when something changes. But how can change something when I only access it for read?

-primitiveValueForKey: only gets the object for some key. But it won’t modify it. So why would/could this cause KVO notifications when using -valueForKey:?

(Of course there is a point, but I don’t see it yet.)

  • 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-18T06:50:31+00:00Added an answer on May 18, 2026 at 6:50 am

    The -primitiveValueForKey: and -setPrimitiveValue:forKey: methods are primarily used by Core Data. In particular, Core Data doesn’t just need to know when you’re going to modify an attribute; it needs to know when you’re going to access it as well, so it can implement faulting.

    Thus Core Data adds -{will,did}AccessValueForKey: methods to use in getters, just as -{will,did}ChangeValueForKey: methods exist for use in setters to act as KVO hooks.

    However, there’s another wrinkle: Core Data actually manages the underlying storage of modeled properties for you as well. So you need some way to manipulate this underlying storage within the barriers established by the -{will,did}{Access,Change}ValueForKey: methods. That’s where -primitiveValueForKey: and -setPrimitiveValue:forKey: come in.

    This is why the standard pattern for implementing Core Data getters and setters, prior to the existence of @property and @dynamic, looked like this:

    // Person.m
    #import "Person.h"
    
    @implementation Person
    
    - (NSString *)name {
        [self willAccessValueForKey:@"name"];
        NSString *value = [self primitiveValueForKey:@"name"];
        [self didAccessValueForKey:@"name"];
    }
    
    - (void)setName:(NSString *)value {
        [self willChangeValueForKey:@"name"];
        [self setPrimitiveValue:value forKey:@"name"];
        [self didChangeValueForKey:@"name"];
    }
    
    @end
    

    Now of course, you can just declare a property and define it as @dynamic if you want Core Data to generate this stuff for you at runtime:

    // Person.h
    @interface Person : NSManagedObject
    @property (nonatomic, readwrite, copy) NSString *name;
    @end
    
    // Person.m
    #import "Person.h"
    
    @implementation Person
    @dynamic name;
    @end
    

    There are some situations though where you still want to manipulate the underlying storage without KVO or fault-firing, however. Thus Core Data provides a new way to get at this as well, also built around property declarations and automatic synthesis:

    // Person.h
    @interface Person : NSManagedObject
    @property (nonatomic, readwrite, copy) NSString *name;
    @end
    
    // Person.m
    #import "Person.h"
    
    @interface Person ()
    @property (nonatomic, readwrite, copy) NSString *primitiveName;
    @end
    
    @implementation Person
    @dynamic name;
    @dynamic primitiveName;
    @end
    

    Note that I put the class continuation in the .m file; it’s not something that code outside Person (or even really code outside -awakeFromInsert and -awakeFromFetch) should touch. But it does let me get at the underlying storage for the “name” property without embedding literal strings in my code, and with the use of the real types.

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

Sidebar

Related Questions

In Core Data, is there some trick to saving changes to managed objects' attributes
Update: mogenerator works, with a template modification The Core Data documentation suggests using the
I've implemented a transient property as below on one of the models in my

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.