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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:34:56+00:00 2026-05-15T22:34:56+00:00

I am using core data in my iPhone app. I have created a simple

  • 0

I am using core data in my iPhone app. I have created a simple class Friend, which derives from NSManagedObject and which uses the following property:

@property (nonatomic, retain) NSString *name;

I am able to add and delete instances of this class to my context and my changes are persistent also.
Now I want to update/modify a Friend-instance and make it persistent again.

But this seems not to work.

Here is piece of code which shows my problem:

//  NSManagedObjectContext *context  = < my managed context> 
//   NSFetchedResultsController *nsfrc= < my fetched result controller>

NSEntityDescription *entity = [nsfrc entity];
NSManagedObject *newManagedObject = [NSEntityDescription 
       insertNewObjectForEntityForName:[entity name]  inManagedObjectContext:context];

Friend *f = (Friend *) newManagedObject;
f.name = @"name1";
//1.  --- here context.hasChanges == 1 ---   ok

NSError *error = nil;
if (![context save:&error]) { ... }
//2.  --- here context.hasChanges == 0 ---   ok

f.name = @"name2";
//3.  --- here context.hasChanges == 0 ---   nok?

if (![context save:&error]) { ... }

At comment 1 everything is fine. I got a new NSManagedObject of the Friend-type and I can change the name property. The context shows me that there is something to save.
After saving the context I see context.hasChanges == 0. Note also that the data is persistent after saving the context.

After comment 2 I change the name property. Now I would expect context.hasChanges == 1 and also after the context save I would expect the new name to be persistent.
But unfortunately It is not. Starting the application again, loads the Friend instance with the name-property = @”name1″.

I cannot find any hint or example inside the core data documentation. So what am I doing wrong?
What do I have to do to update/modify an existing Friend-instance and to make it persistent?

The only solution I see is to delete the entry, change it, and add it again. But I don’t think that this is the correct way for it.

Thanks!

  • 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-15T22:34:57+00:00Added an answer on May 15, 2026 at 10:34 pm

    Finally found the solution! For my above question I removed all unnessesary code (unfortunately I also removed my problem). So, to complete this thread:
    My Friend-class also has a member:

    @property (nonatomic) int duration;
    

    In my test environment I also set the duration (whenever I set the name). This seems to be the reason why the context is not able to recognize any change. If I change the property to

    @property (nonatomic, retain) NSNumber duration;
    

    everything worked fine. Note that my xdatamodel has a property duration of type Int32.
    What I not understand is, why everything worked for the first [context save];. But this is ok for me for now.

    To give some good advice here:

    Do NOT generate your xdatemodel out of your NSManagedObject-derived class (as I did).
    Instead create your xdatemodel and then generate your class out of your model (Xcode->Design->DataModel->Copy Obj-C2.0..)!
    (Update 03/2011: Generating the Classes out of the Model works like a charm in XCode 4.0!)

    I wish I had known this early on this beautiful sunday morning.
    Good evening!

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

Sidebar

Ask A Question

Stats

  • Questions 523k
  • Answers 523k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You probably want a custom single page template. Adding a… May 16, 2026 at 9:34 pm
  • Editorial Team
    Editorial Team added an answer In EF (3.5 and 4.0) FKs MUST point to Primary… May 16, 2026 at 9:34 pm
  • Editorial Team
    Editorial Team added an answer The variable VAR contains -e xyz, if you access the… May 16, 2026 at 9:34 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have setup Core Data for an iPhone app without an instance of NSFetchedResultsController.
I'm using core data on an iPhone application. I have multiple persisntent stores that
I am using Core Data for my iPhone app. My attributes are set with
My iPhone app will have read-only system data AND read/write user data (stored either
I'm diving in to iPhone development and I'm building an iPhone app that uses
I'm tinkering around with a iPhone word app where I am using a DAWG
I have an iPhone VOIP app that copes with multi-multi transmit and receive (ie
In core data for the iPhone, I was getting all sorts of errors trying
I have a simple entity called Store built in Xcode's data modeler for use
I'm developing for iphone-sdk 2.2.1 (so no CoreData cry ). So I'm using 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.