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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:52:14+00:00 2026-05-14T04:52:14+00:00

I have a table view that is managed by an NSFetchedResultsController. I am having

  • 0

I have a table view that is managed by an NSFetchedResultsController. I am having an issue with a find-or-create operation, however. When the user hits the bottom of my table view, I am querying my server for another batch of content. If it doesn’t exist in the local cache, we create it and store it. If it does exist, however, I want to append that data to the fetched results controller and display it. I can’t quite figure that part out.

Here’s what I’m doing thus far:

  1. The NSFetchedRequestController when initialized queries for the latest 100 results from the database (using setFetchLimit:). Even if there are 1000 rows, I only want 100 accessible at first.
  2. Passing the returned array of values from my server to an NSOperation to process.
  3. In the operation, create a new managed object context to work with.
  4. In the operation, I iterate through the array and execute a fetch request to see if the object exists (based on its server id).
  5. If the object doesn’t exist, we create it and insert it into the operations’ managed object context.
  6. After the iteration completes, we save the managed object context, which triggers a merge notification on my main thread.

During the merge, the newly created objects from step 4 are inserted into the table, but any object that already existed and was just fetched does not. Here’s the relevant code from my NSOperation

for (NSDictionary *resultsDict in self.results)
{
    NSNumber *dbID = [NSNumber numberWithLong:[[resultsDict valueForKey:@"id"] longValue]];

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    [fetchRequest setEntity:[NSEntityDescription entityForName:kResultEntityName inManagedObjectContext:moc]];
    [fetchRequest setPredicate:[NSPredicate predicateWithFormat: @"(dbID == %@)", dbID]];

    NSError *error = nil;

    NSManagedObject *newObject = nil;
    // Query the data store to see if the object exists
    newObject = [[moc executeFetchRequest:fetchRequest error:&error] lastObject];
    [fetchRequest release];

    // If it doesn't exist, create it.
    if ((tweet == nil))
    {
        // Create the NSManagedObject and insert it into the MOC.  
    }
}

What I want to pass to my main thread is the newly created objects plus any existing objects that may have been fetched in the fetch request each time the loop iterates.

I feel like it’s something simple I’m missing, and could use a nudge in the right direction.

  • 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-14T04:52:15+00:00Added an answer on May 14, 2026 at 4:52 am

    At this point, any objects that weren’t locally cached in my Core Data store before will appear, but the ones that previously existed do not come along for the ride.

    Can you explain this a little? I am not sure what you mean by the ones that previously existed. Is it objects that didn’t match the filter on your table that now do after the retrieval or are you saying that the previous objects disappear from the table?

    Also, how are you implementing the delegate methods for the NSFetchedResultsController? Are you doing a simple table reload or are you inserting/moving rows?

    Update

    There are a couple of ways to do this but they would require some experimentation on your part. I would first play with the idea of “touching” the objects that were fetched. Perhaps updating a ‘lastAccessed’ date or something so that these objects will come across the merge as “updated”. I suspect that is the easiest path.

    Baring that, another option would be to broadcast a notification of those objects back to the main thread (using their NSManagedObjectID as the carrier across the thread boundaries) so that you can manually update them; however that is less than ideal.

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

Sidebar

Related Questions

I have a table view that displays managed objects (Tasks). I'd like to fetch
In my iPhone application I have a table view. When user taps any row,
I have a view that is joining two tables and ordering by the first
Here's my case: I have a table view showing contacts. Add button in the
I have a grouped table view with textfields in the tableview. For the keyboard
I have a name of table or view in PostgreSQL database and need to
I have a situation where I build a view with a table and another
I have a view that contains a UITableView and a UILabel which works perfectly
I've got a fetched results controller handling a table view, and I'm having a
I have a table view where cells can display a variable amount of information.

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.