Note that there are some explanatory texts on larger screens.

plurals
  1. POSection names from NSFetchedResultsController don't match the managed object values
    text
    copied!<p>I'm using an NSFetchedResultsController to populate a UITableView with results from a moderately sized Core Data store of ~1500 entities. The results controller is fairly standard - some "hot spots" for potential bugs aren't true of this setup.</p> <ul> <li>Managed object context created on the same (main) thread as its used on</li> <li>No cache is used (because the sort changes frequently)</li> <li>A sectionNameKeyPath is used to split the results into sections</li> </ul> <p>My section results, however, are very odd. For example, consider this method used to set the titles for the section header views:</p> <pre><code>- (NSString *)titleForHeaderInSection:(NSInteger)section { id &lt;NSFetchedResultsSectionInfo&gt; sectionInfo = [[self.resultsController sections] objectAtIndex:section]; return [sectionInfo name]; // &lt;------- Stopped at breakpoint here } </code></pre> <p>I've stopped at the indicated line using a breakpoint and, using GDB, examined the following:</p> <pre><code>(gdb) po [[self resultsController] sectionNameKeyPath] reviewDateString (gdb) print section $11 = 1 (gdb) print (int) [sectionInfo numberOfObjects] $12 = 4 (gdb) po [sectionInfo name] Wednesday, September 8th 2010 (gdb) po [[[sectionInfo objects] objectAtIndex:0] valueForKey:@"reviewDateString"] Sunday, February 13th 2011 (gdb) po [[[sectionInfo objects] objectAtIndex:1] valueForKey:@"reviewDateString"] Sunday, February 13th 2011 (gdb) po [[[sectionInfo objects] objectAtIndex:2] valueForKey:@"reviewDateString"] Sunday, February 13th 2011 (gdb) po [[[sectionInfo objects] objectAtIndex:3] valueForKey:@"reviewDateString"] Sunday, February 13th 2011 </code></pre> <p>The issue should be evident - why doesn't [sectionInfo name] match the values of the sectionNameKeyPath for each managed object in the section? The objects in the section appear to be properly grouped, the section name just isn't correctly set.</p> <p>The results are even more odd if you look at this:</p> <pre><code>(gdb) po [[self resultsController] indexPathForObject:(id)[[sectionInfo objects] objectAtIndex:0]] &lt;NSIndexPath 0x6615660&gt; 2 indexes [459, 4294966310] </code></pre> <p>Now obviously, from the above, the NSIndexPath returned should be [1,0], not this bogus value.</p> <p>I'm completely stumped. Anyone have any ideas? I'll be watching this question in case you need more information.</p> <p><strong>[Edit 1]</strong></p> <p>The one odd thing about my NSFetchedResultsController setup is that I recreate (release and alloc/init a new one) the results controller in response to a UISegmentedControl's selection changing. This is done in order to change the sortDescriptors of the fetch request and sectionNameKeyPath, so that the overall sort changes.</p> <p><strong>[Edit 2]</strong></p> <p>The resultsController method is just the property accessor for the NSFetchedResultsController that I'm using, generated by @synthesize.</p> <p>The expected values for the section names are given already - the section names should be equal to the values for the @"reviewDateString" key (which is the sectionNameKeyPath) that I showed just below "po [sectionInfo name]", so for this case they should be "Sunday, February 13th 2011".</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload