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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:50:42+00:00 2026-06-13T04:50:42+00:00

I am trying to use Core Data in my application. I want to store

  • 0

I am trying to use Core Data in my application. I want to store an attribute “totalKM”.

to store my attribute I use these lines:

Model *event = (Model *)[NSEntityDescription insertNewObjectForEntityForName:@"Model" inManagedObjectContext:managedObjectContext];
int number = 4;
[event setTotalKM:[NSNumber numberWithDouble:number]];

to read my attribute I use these:

Model *event = (Model *)[NSEntityDescription insertNewObjectForEntityForName:@"Model" inManagedObjectContext:managedObjectContext];
NSNumber *number = [event totalKM];

My attribute “totalKM” is always default value, O. And I have no exception. Am i missing something?

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-06-13T04:50:43+00:00Added an answer on June 13, 2026 at 4:50 am

    insertNewObjectForEntityForNamethis method use to put model to context.

    this is a new object.

    the right way is:

    Set new one

    Model *event = (Model *)[NSEntityDescription insertNewObjectForEntityForName:@"Model" inManagedObjectContext:managedObjectContext];
    
    int number = 4;
    
    [event setTotalKM:[NSNumber numberWithDouble:number]];
    
    //save change if need
    NSError *error = nil;
    
    if (![self.manageObjectContext save:&error]) {
        NIDERROR(@"save managedContext error :%@",error);
    }
    

    fetch object progress

    When you need to get a model form coredate.u need 2 fetch use fetch

    like this dome

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
    [fetchRequest setEntity:[NSEntityDescription entityForName:@"Board"
                                        inManagedObjectContext:self.manageObjectContext]];
    //set fetch conditions
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"board_id == %@", aBoardID];
    [fetchRequest setPredicate:predicate];
    
    NSError *error = nil;
    
    NSArray *results = [self.manageObjectContext executeFetchRequest:fetchRequest error:&error];
    
    if (error) {
        NIDERROR(@"fetch board error.\n board id: %@ \n error:%@", aBoardID, error);
        return nil;
    }
    
    Model *model = results[0];
    
    NSLog(@"%@",model.totalKM)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use two different Core Data Models in a iPhone application,
I'm trying to use core data in a multi thread way. I simply want
I am trying to use Core Data in an app I'm working on; in
I am trying to delete an entity in core data. I use the following
I'm trying to make my first application using Objective C + Core Data, but
I am trying to learn Codeigniter. I am trying to use application/core/MY_Controller in my
I'm using Core Data in my first iPhone application and trying to understand NSFetchedResultsController.
I'm trying to convert an existing app to use core data. I've set up
I am trying to use drush to update my drupal core but in some
I am trying use gem tire to search in my application. I have tables

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.