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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:10:37+00:00 2026-05-22T23:10:37+00:00

In Core Data, is there some trick to saving changes to managed objects’ attributes

  • 0

In Core Data, is there some trick to saving changes to managed objects’ attributes when the changes were made with setPrimitiveValue versus the object’s regular accessor methods?

I’ve switched to using setPrimitiveValue and setPrimitiveAttributeName in a few scenarios in order to avoid triggering my FRC’s notification methods (controllerWillChangeContent, controllerDidChangeObject, etc.). In both cases, after making changes to the core data objects and saving the managed object context, the changes look like they were made (i.e I can see the changes with NSLog) but they are actually lost (i.e. if I exit the application in the simulator and rerun it, the FRC reloads, and the attributes I thought I changed are gone).

The save code is copied from Apple examples, and the managed object classes for my Core Data entities are as-generated by Xcode. Everything I’ve read from Apple and on this site suggests this is a valid use of the setPrimitive methods, though I admit I must be lacking a some understanding of how these setPrimitive functions really work…

Code:

// header file for Managed Object sub class generated by xcode from my core data entity:
#import <CoreData/CoreData.h>
@interface PlannedItem :  NSManagedObject  
{
}

@property (nonatomic, retain) NSNumber * ptType;
@property (nonatomic, retain) NSNumber * whenOrder;
@end

// .m file for Managed Object subclass
#import "PlannedItem.h"
@implementation PlannedItem 

@dynamic ptType;
@dynamic whenOrder;

@end

// trying to use setPrimitiveValue or even setPrimitiveWhenOrder to modify
// this is in my view controller
// p is a pointer to PlannedItem
int oldOrder = [p.whenOrder intValue];
[p setPrimitiveValue:[NSNumber numberWithInt:(oldOrder +1)] forKey:@"whenOrder"];


// later on in same method, save is executed.  
if (![[self managedObjectContext] save:&error]) {
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}
NSLog(@"Saved");    

Thanks for any tips

  • 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-22T23:10:37+00:00Added an answer on May 22, 2026 at 11:10 pm

    If you don’t want the code in the notification handlers to execute (BTW, why would you want that?), it might be easier to disable that, instead of completely avoiding the notifications. Also, remember that Core Data uses those notifications to update your relationships and maintain coherence in your model when you make changes.

    In your view controller, setup a boolean and set it according to your need to execute the notification handler code or not. Then, in your handlers check that flag, e.g.:

    - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
        if (notificationIgnored) {
            return;
        }
        // rest of the code...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Core Data managed object model, I have an entity Foo with a
I am having some issue with understanding of Core Data. In my program there
I'm new with Core Data and there are some issues that I don't understand
There might be applications that are not suited for Core Data - image manipulation
What’s considered ‘best practice’ when saving Address Book contacts in Core Data? I’m writing
I have some basic questions about core data (which I am new to) and
I was having problems adding objects to one of my core data objects that
I've noticed that in my Core Data data model, some entities are (in the
My situation is simple: I have some records in my core data store. One
I'm new to Core Data, and am struggling with some of it conceptually (relative

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.