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

  • Home
  • SEARCH
  • 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 950963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:39:08+00:00 2026-05-15T23:39:08+00:00

Just run into a tricky NSFetchedResultsController problem. The following code works fine in all

  • 0

Just run into a tricky NSFetchedResultsController problem.

The following code works fine in all cases EXCEPT for the very first entry to the Core Data database when it reports 2 rows!

id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
numberOfRows = [sectionInfo numberOfObjects];

If I add additional entries these are reported correctly.
And if I delete both of the 2 initial rows it works fine.

Any suggestions?
If it’s any help, by using:

  -com.apple.CoreData.SQLDebug 1

I can see there was 1 INSERT and 2 SELECTs.

Also, this problem doesn’t seem happen if I’ve already visited the view containing the NSFetchedResultsController code (i.e. before doing the INSERTs).

====
UPDATE 1:
Wonder if this walk through the code will help…
1. ViewController A starts a background NSOperation which does a download
2. When this completes it sends a notification to the AppDelegate
3. When the AppDelegate gets this notification it imports the data (doing a check to make sure it’s on the main thread before doing so)

Here’s the relevant bit of the importerDidSave code (where this technique was taken from):

- (void)importerDidSave:(NSNotification *)saveNotification {  
   NSLog(@"In importerDidSave...");  
   if ([NSThread isMainThread]) {  
     NSLog(@"... on Main Thread.");     
     NSLog(@"Number of NSFetchedResultsController rows BEFORE: %d", [[[fetchedResultsController sections] objectAtIndex:0] numberOfObjects]);  
     [self.managedObjectContext mergeChangesFromContextDidSaveNotification:saveNotification];  
     NSLog(@"Number of NSFetchedResultsController rows AFTER: %d", [[[fetchedResultsController sections] objectAtIndex:0] numberOfObjects]);  

which outputs:

... on Main Thread.  
Number of NSFetchedResultsController rows BEFORE: 1  
Number of NSFetchedResultsController rows AFTER: 3
  • 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-15T23:39:09+00:00Added an answer on May 15, 2026 at 11:39 pm

    Don’t rely on direct SQL debugging. Core Data’s use of SQL is so buried behind the objects (it doesn’t even use SQL all the time) that you can’t tell the state of the object graph by looking at the SQL.

    Most likely, you have two objects in the section but one is in memory and one in the persistent store. Only the persisted object would be apparent in the SQL debug. You could have thousands of objects in the graph and thousands of rows in a table section but until the objects are persisted, they won’t show in the SQL. Moreover, the pattern of SQL inserts and deletes will not directly reflect the insertions and deletes of the object graph.

    In short, the SQL debug is pretty useless for debugging Core Data and you should ignore it in the vast majority of cases.

    If the fetched results controller reports two objects in the section then there are two objects in the section. Where the extra object came from, I can’t say without more information.

    Check:

    1. Your section key if any. If your sections are misconfigured you will have rows where you don’t expect them.
    2. Check your insertion to see if you are duplicating insertions.

    You can confirm whether FRC is correct by manually performing the same fetch it uses yourself and seeing what gets returned. Sort the return on each section key and you can see how many objects appear in the section.

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

Sidebar

Related Questions

I've just started to use linq to sql and have run into a problem
I've just run into a display glitch in IE6 with the ExtJS framework. -
This is an odd thing I've just run into. I have a web application
We've just updated ASP.NET from Preview 3 to Preview 5 and we've run into
Python 2.5.1 http://www.cgsecurity.org/wiki/After_Using_PhotoRec I've just run PhotoRec and the code given as a way
I'm trying to run a 3d array but the code just crashes in windows
In Mootools, I'd just run if ($('target')) { ... } . Does if ($('#target'))
If I just want to run the new style web services on, say a
My employer just asked me to run a timed batch process in a Java
I just wanted some opinions from people that have run Selenium ( http://selenium.openqa.org )

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.