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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:22:04+00:00 2026-05-29T09:22:04+00:00

I am retrieving a fetch from my core data database and trying to iterate

  • 0

I am retrieving a fetch from my core data database and trying to iterate through the data and make changes to the data, if necessary. When I change the data in the results array, it turns out that my database is changing in the back end as well, without doing a save. I am wondering what would be a good practice to use to change the data without affecting the back end data.

Here is the code I change the data with:

 self.singleDayDataPointsForGraph = [[self fuelPurchaseDataForTimePeriodInMonths:self.numberOfMonthsForGraphView] mutableCopy];
    for (int i = 0; i < self.singleDayDataPointsForGraph.count; i++) {
        FuelPurchase *currentFuelPurchase = [self.singleDayDataPointsForGraph objectAtIndex:i];
        if (i <  self.singleDayDataPointsForGraph.count + 1 && self.singleDayDataPointsForGraph.count >= 2) {
            FuelPurchase *purchaseToCompare = [self.singleDayDataPointsForGraph objectAtIndex:i + 1];
            NSDate *firstDate = currentFuelPurchase.dateTimeStamp;
            NSDate *secondDate = purchaseToCompare.dateTimeStamp;
            NSDateFormatter *dateComparisonFormatter = [[NSDateFormatter alloc] init];
            [dateComparisonFormatter setDateFormat:@"yyyy-MM-dd"];

            if([[dateComparisonFormatter stringFromDate:firstDate] isEqualToString:[dateComparisonFormatter stringFromDate:secondDate]] ) {
                float firstValue = [purchaseToCompare.fillSavings floatValue];
                float secondValue = [currentFuelPurchase.fillSavings floatValue];
                purchaseToCompare.fillSavings = [NSNumber numberWithFloat:(firstValue + secondValue)];
                [self.singleDayDataPointsForGraph removeObjectAtIndex:i];
            }
        }

The fuelPurchaseDataForTimePeriodInMonths: method is what performs the fetch and returns an NSArray of results. self. singleDayDataPointsForGraph is an NSMutableArray that stores the results array as a mutable copy. This method basically checks two entries in the database to see if they are the on the same day and if they are, then it adds the fuel purchase amounts to each other and deletes one of the records. I don’t want this to change my back end data, but it is.

Thanks very much.

  • 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-29T09:22:05+00:00Added an answer on May 29, 2026 at 9:22 am

    It is doing the right thing. If you take a core data object and modify it, it will reflect immediately whether you save it ot not. The saving part ensures, that if you quit the application and come back the data is saved as well.

    So for your situation, I would avoid modifying the actual core data object. Rather create a structure which imitates the core data object and modify that structure.

    Example, say my coredata object is Person with attributes name and age.

    The object a get from a fetch is say
    person1.

    You have a class PersonSub with same attributes.

    Now you can create

    PersonSub *personSub = [[PersonSub alloc] init]; //You can create a custom init to initilize from Person core data if you like.
    personSub.name = person1.name;
    personSub.age = person1.age;
    

    Now you can modify as follows

    personSub.age = personSub.age + 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to fetch data from SQLite database(NSArray of strings) and populate the
I am retrieving data from an Oracle database and binding the same to a
I'm trying to re-format / re-order the array results I'm getting from mysql_fetch_array() to
When retrieving data from MySQL, the PHP array output has both numeric and name
I have a problem with retrieving data from a database using PHP statements. At
I'm having trouble retrieving data from my database using Spring Jdbc. Here's my issue:
I am having problem with $_GET array. More precisely I'm retrieving data from mysql
I am retrieving 3 fields from a database, and by default, only the username
I'm retrieving a float value from a mysql database on a php page (2.5,
I am getting the following error when retrieving data from a rest data source

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.