Appending data to NSFetchedResultsController during find or create loop

Posted by Justin Williams on Stack Overflow See other posts from Stack Overflow or by Justin Williams
Published on 2010-04-07T05:16:30Z Indexed on 2010/04/07 5:23 UTC
Read the original article Hit count: 395

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. Passing the returned array of values from my server to an NSOperation to process.
  2. In the operation, create a new managed object context to work with.
  3. In the operation, I iterate through the array and execute a fetch request to see if the object exists (based on its server id).
  4. If the object doesn't exist, we create it and insert it into the operations' managed object context.
  5. After the iteration completes, we save the managed object context, which triggers a merge notification on my main thread.

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.

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

© Stack Overflow or respective owner

Related posts about core-data

Related posts about nsfetchedresultscontrolle