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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:53:56+00:00 2026-05-18T11:53:56+00:00

I am facing a very weird problem with coredata. I have an item managed

  • 0

I am facing a very weird problem with coredata.
I have an item managed with ids and i’m trying to update a dynamic property which is a simple NSNumber. I do this as always, in my item class:

- (int) hits{
    return [self.hitNS intValue];
}

- (void) setHits:(int)h{
    self.hitNS=[NSNumber numberWithInt:h];
}

Basically, i create my managed, object with this method:

[NSEntityDescription insertNewObjectForEntityForName:@"item" 
    inManagedObjectContext:[self getManagedObjetContextForCurrentThread]];

Then I update my hits, after I receive some data from the server.
CoreData tells me it updated the item, but when I access the item again:

-(NSArray *) getStoredEntities:(NSString*)entity withPredicate:(NSPredicate*)predicate 
{       
    NSManagedObjectContext *moc=[self getManagedObjetContextForCurrentThread];
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:[NSEntityDescription entityForName:entity
        inManagedObjectContext:moc]];
    if (predicate)
        [request setPredicate:predicate];
    NSError *error = nil;
    NSArray *fetchResults = [moc executeFetchRequest:request error:&error]; 
    [request release];
    return [fetchResults objectAtIndex:0];
}

Item *i=(Item*)[self getStoredEntity:@"Item" 
    withPredicate:[NSPredicate predicateWithFormat:@"(id==%@)", itemId]];

my property item.hits is not set to the new value, I get the old one.

What’s driving me nuts is that When I kill my app, and start again, my object is there and it works well. If y update my hits count, I get the good value…

So I think my problem is in some way connected to the first insertion of my object in CoreData…
Is there a cache I’m not seeing? Do I have to do something to “invalidate” my object?

Some help there would be really great!

  • 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-18T11:53:57+00:00Added an answer on May 18, 2026 at 11:53 am

    That means your get/set managed contexts aren’t synced.

    After you save a context the NSManagedObjectContextDidSaveNotification is sent and all other contexts interested in these changes have to observe this notification and then use mergeChangesFromContextDidSaveNotification to synchronize.

    • 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.