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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:33:37+00:00 2026-05-13T18:33:37+00:00

Update: Currently looking into NSSET’s minusSet links: Comparing Two Arrays Hi guys, Could benefit

  • 0

Update: Currently looking into NSSET’s minusSet
links: Comparing Two Arrays

Hi guys,

Could benefit from your wisdom here..

I’m using Coredata in my app, on first launch I download a data file and insert over 500 objects (each with 60 attributes) – fast, no problem.

Each subsequent launch I download an updated version of the file, from which I need to update all existing objects’ attributes (except maybe 5 attributes) and create new ones for items which have been added to the downloaded file.

So, first launch I get 500 objects.. say a week later my file now contains 507 items..

I create two arrays, one for existing and one for downloaded.

    NSArray *peopleArrayDownloaded = [CoreDataHelper getObjectsFromContext:@"person" :@"person_id" :YES :managedObjectContextPeopleTemp];
NSArray *peopleArrayExisting = [CoreDataHelper getObjectsFromContext:@"person" :@"person_id" :YES :managedObjectContextPeople];

If the count of each array is equal then I just do this:

    NSUInteger index = 0;
if ([peopleArrayExisting count] == [peopleArrayDownloaded count]) {
    NSLog(@"Number of people downloaded is same as the number of people existing");
    for (person *existingPerson in peopleArrayExisting) {
        person *tempPerson = [peopleArrayDownloaded objectAtIndex:index];
        //  NSLog(@"Updating id: %@ with id: %@",existingPerson.person_id,tempPerson.person_id);
        // I have 60 attributes which I to update on each object, is there a quicker way other than overwriting existing?
        index++;
    }
} else {
    NSLog(@"Number of people downloaded is different to number of players existing");

So now comes the slow part.

I end up using this (which is tooooo slow):

            NSLog(@"Need people added to the league");
        for (person *tempPerson in peopeArrayDownloaded) {
            NSPredicate *predicate = [NSPredicate predicateWithFormat:@"person_id = %@",tempPerson.person_id];
            //  NSLog(@"Searching for existing person, person_id: %@",existingPerson.person_id);
            NSArray *filteredArray = [peopleArrayExisting filteredArrayUsingPredicate:predicate];
            if ([filteredArray count] == 0) { 
                NSLog(@"Couldn't find an existing person in the downloaded file. Adding..");
                person *newPerson = [NSEntityDescription insertNewObjectForEntityForName:@"person" inManagedObjectContext:managedObjectContextPeople];

Is there a way to generate a new array of index items referring to the additional items in my downloaded file?

Incidentally, on my tableViews I’m using NSFetchedResultsController so updating attributes will call [cell setNeedsDisplay];
.. about 60 times per cell, not a good thing and it can crash the app.

Thanks for reading 🙂

  • 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-13T18:33:37+00:00Added an answer on May 13, 2026 at 6:33 pm

    I’ll begin by saying that I’m still new to using the Core Data framework, but my guess is that your problem lies in the for loop you’ve posted.

    If you look at your loop, each time it executes it creates a new NSPredicate object and then filters your existing array looking for matches. On a small data set this technique would work with seemingly small performance losses; however, with your large data set you will end up spending a lot of time creating NSPredicate objects that only differ in the name you’ve provided. I would suggest that you look at how to create a single predicate and then use variable substitution to perform the search. For information about variable use in predicates check out: http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdImporting.html#//apple_ref/doc/uid/TP40003174

    As a side note, you may also consider how you’ve sorted your data and how you are performing the search operation. And another thing I noticed is that you don’t release your NSPredicate object, so you’re just tossing memory away too.

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

Sidebar

Related Questions

Currently looking to extract data from 2 tables and insert into another. Tables as
I am a newborn programmer who is currently looking into the Insert, Update and
I'm currently preparing a major Program-Update and ran into following problem: I've got a
I'm currently looking into automating a flex build so that we can get it
I am currently looking into how I can manage a high number of bids
I'm currently looking into possible ways we can refactor our codebase, to make it
I currently have two fairly long select statements, identical apart from the fact that
I am currently looking into implementing a client which will use an existing extensive
I am currently looking into different ways to support distributed model objects (that is,
I'm currently looking into getting my android app to work on Kindle Fire. I've

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.