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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:30:10+00:00 2026-06-02T20:30:10+00:00

I have an array with 36 rows which was fetched from CoreData. Each row

  • 0

I have an array with 36 rows which was fetched from CoreData. Each row has three attributes: podNumber, pieceNumber, and colorNumber.

What I want to do is shuffle the results in groups of six. Such that each pod has six pieces, and these will be shuffled for that group.

I am able to do this efficiently; however when I update the CoreData with the randomized values the performance is noticeably sluggish. I would say it takes a 1-1.5 seconds to complete the loop.

I experimented with two methods: 1) deleting the old array from CoreData and adding a new one 2) searching for the unique row in CD and updating

I found the first method is slightly faster. Does anyone have any insight as to how I could speed this up? Is there a more efficient way to update a large batch of core data. Do I need to make it a background process and how would that work.

Thanks.
MJ

Here is method one:

//Fetch them all and then delete them all
NSFetchRequest * fetchPieceColors = [[NSFetchRequest alloc] init];
[fetchPieceColors setEntity:[NSEntityDescription entityForName:@"PieceColors" inManagedObjectContext:managedObjectContext]];
[fetchPieceColors setPredicate:[NSPredicate predicateWithFormat:@"(game = %@)",games]];
[fetchPieceColors setIncludesPropertyValues:NO]; 

NSError * error = nil;
NSArray * pieceColor = [managedObjectContext executeFetchRequest:fetchPieceColors error:&error];
[fetchPieceColors release];
for (NSManagedObject * piece in pieceColor) {
    [managedObjectContext deleteObject:piece];
}
NSError *saveError = nil;
[managedObjectContext save:&saveError];



//Add back
for (int b=0;b<6;b++) {
    for (int j=0;j<6;j++) {
        NSError *error;
        NSManagedObject *fetchPieceColors = [NSEntityDescription
                                   insertNewObjectForEntityForName:@"PieceColors" 
                                   inManagedObjectContext:managedObjectContext];
        [fetchPieceColors setValue:[NSNumber numberWithInt:b] forKey:@"podNumber"];
        [fetchPieceColors setValue:[NSNumber numberWithInt:j] forKey:@"pieceNumber"];
        [fetchPieceColors setValue:[shuffledArray objectAtIndex:(b*6)+j] forKey:@"colorNumber"];
        [fetchPieceColors setValue:games forKey:@"game"];


        if (![managedObjectContext save:&error])
        {
            NSLog(@"Problem saving: %@", [error localizedDescription]);
        }
    }
}
  • 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-02T20:30:11+00:00Added an answer on June 2, 2026 at 8:30 pm

    As timthetoolman pointed out it is the IO of hitting the disk that is the killer. What you need to do is get all of the data in memory, make your edits and then save it all at once.

    The Efficiently Importing Data of the Core Data Programming Guide has some useful hints on what you can do to improve performance.

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

Sidebar

Related Questions

I have both matrices containing only ones and each array has 500 rows and
I have an array of data from which I would like to extract rows
I have an HTML table in which each data row has a unique id
I have an array which can be any size (in rows) but is always
I have an array which populated by a cookie. The length differ each time.
I have two databases($db1, $db2) with exact table structure(table1). $db2.table1 has new rows which
I have an array of elements: markers and a table which updates it's rows
I have a function which returns only one row as array. I give a
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have array of strings, String[] data and it's 10 elements has value P

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.