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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:42:02+00:00 2026-05-21T14:42:02+00:00

I’m working with a subclass of NSManagedObject. Actually, it inherits from a class that

  • 0

I’m working with a subclass of NSManagedObject. Actually, it inherits from a class that inherits from a class that itself inherits from NSManagedObject (that shouldn’t be a problem, right?).

The problem

After I make changes to the properties of the object, the object remembers the changes for its lifetime, but the changes are never saved to the database.

How Do I Know This?

I know this because:

  • when I restart the app, the changes I’ve made are lost.
  • telling the context to refresh the object – AFTER I’ve made changes to the object and told the context to save – sets the object’s values back to their original state before I made the changes.
  • when running the app in the simulator, I can look at the sqlite database file in the Finder, and it’s modified date isn’t updated when I attempt to save the context.

Nothing is being written to the database!

Context

I’m using the auto-generated delegate methods to create the store coordinator and the context. Then I’m passing the context to the view controllers in their init methods, as recommended in the docs. The store is SQLite.

I am able to successfully insert objects into the database and read them. I can even make property changes to the newly inserted object and save it successfully. I simply don’t seem to be able to update object properties when the object is pulled back out of the database.

The object is fetched from the store via a relationship from another object. After making changes to its properties, I call the context’s save method. However, before doing so, I call the object’s isUpdated method and the context’s hasChanges method, and both return false. Shouldn’t they return true since I’ve just made changes to the object’s properties but haven’t saved the context?

More

If I call the object’s committedChanges method before saving the context, however, passing in the names of the properties that I’ve changed, I get back the correct values of the properties. I’m not sure what this means. I would have thought that this means that the object’s new property values have been successfully saved, but clearly they are not saved.

I know that the result objects is registered with a context. If I call

[[result managedObjectContext] refreshObject:result mergeChanges:YES];

the object reverts back to the original property values. This means that the context is there and that it is the same context from which the record was fetched. And it means that the new property values are never written tot he database.

Some Code

Here’s the code where I’m poking around with all of these things. There are other places in my code where I’m making property changes, but the changes are never saved.

- (IBAction)statusControlChanged:(UISegmentedControl *)control {
WCAAssessmentResult *result = [self currentResult];

    /* printing the existing property values */
    if (![result.complete boolValue]) NSLog(@"result is in progress!");
    else if ([result.passed boolValue]) NSLog(@"result is passed!");
    else NSLog(@"result is not passed!");

    /* changing the property values */
    switch (control.selectedSegmentIndex) {
        case 0:
            NSLog(@"setting incomplete");
            result.complete = [NSNumber numberWithBool:NO];
            break;
        case 1:
            NSLog(@"setting passed");
            result.passed = [NSNumber numberWithBool:YES];
            result.complete = [NSNumber numberWithBool:YES];
            break;
        case 2:
            NSLog(@"setting failed");
            result.passed = [NSNumber numberWithBool:NO];
            result.complete = [NSNumber numberWithBool:YES];
            break;
        default:
            break;
    }

    /* this method always returns an empty dictionary */
    NSLog(@"%@", [result changedValues]);

    /* this method returns the values that I just set */
    NSLog(@"%@", [result committedValuesForKeys:[NSArray arrayWithObjects:@"complete", @"passed", nil]]);

    /* isUpdated returns false */
    if (![result isUpdated]) {
        NSLog(@"result is not updated?! WTF!?!?");
    }

    /* hasChanges returns false */
    if (![[result managedObjectContext] hasChanges]) {
        NSLog(@"context has no changes!? WTF!?!?");
    }

    /* saving the context produces no error */
    NSError *error = nil;
    if (![[result managedObjectContext] save:&error]) {
        NSLog(@"save failed");
        NSLog(@"%@",[error description]);
    }
}

A Twist

If I create a new result object by inserting a new record into the context, I can set that object’s properties and they are saved successfully. In the above code, I’m fetching the object as a member of a to-many association from another object. Is that a clue?

I’m tearing my hair out over this. What the hell could be going wrong here?

What’s NOT The Problem

  • I’ve logged the object’s class, and it is indeed the correct class
  • I’ve made sure that the managedObjectContext I’m saving is the same as the object’s context
  • I haven’t made any changes to the auto-generated setter/getter methods of my managed object classes
  • I’ve tried using the setValue:forKey: method instead of object’s properties
  • I’ve used the -com.apple.CoreData.SQLDebug 1 argument to log Core Data SQL, and no SQL is logged when I update and save the object’s properties
  • 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-21T14:42:03+00:00Added an answer on May 21, 2026 at 2:42 pm

    I do not really understand your statement

    WCAAssessmentResult *result = [self currentResult];
    

    Indeed, if you are accessing a to-many relationship from an object, you should get back a set, not an object. Anyway, without seeing the code it’s hard to tell. The problem you are experiencing may or may not lie there.

    I would rather expect in your code something like the following snippet to access objects belonging to a to-many relationship. I assume that yourObject is the object you use to access the WCAAssessmentResult objects in the to-many relationship, which I call results.

    NSMutableSet *resultObjects = [yourObject mutableSetValueForKey:@"results"];
    NSPredicate *predicate = ...
    [resultObjects filterUsingPredicate:predicate];
    
    for(WCAAssessmentResult *result in resultObjects){
    
       // modify as needed the current result object
    
    }
    
    NSError *error = nil;
    if (![managedObjectContext save:&error]) {
            NSLog(@"save failed");
            NSLog(@"%@",[error description]);
    }
    

    Did you verify that the managedObjectContext you are using to save the object is valid (not nil) ?

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a bunch of posts stored in text files formatted in yaml/textile (from
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.