I am currently facing a (to me) strange issue as follows:
I have a child MOC (NSManagedObjectContext
) with about two dozen MOs (NSManagedObject
s). Each MO has an optional Boolean attribute flag
. All of these are set to @(NO)
. fetchedResultsController
is an NSFetchedResultsController
which fetches these MOs, whose managedObjectContext
is moc
and whose sectionNameKeyPath
is @"flag"
. fetchedResultsController
also has an sort descriptor on flag
(and another secondary sort attribute).
After running these lines of code
NSAssert(!moc.hasChanges, nil); // no unsaved changes
BOOL flag = [fetchedResultsController performFetch: &error];
NSAssert(flag && (error == nil), nil); // no errors
I observe the following:
fetchedResultsController.fetchedResults
contains as many MOs as doesmoc
and all their flags are@(NO)
(as one would expect).fetchedResultsController.sections.count
andfetchedResultsController.sectionIndexTitles.count
are both1
(as one would expect, since allflag
s have the same value).fetchedResultsController.sectionIndexTitles[0]
is@"1"
.
The third item appears wrong to me. I would have expected @"0"
(since this is the capitalized first letter of [@(NO) description]
).
What could be wrong here and how can I obtain the right section index title in this case?
UPDATE I now looks as if the problem may be (still) related to employing flag
(an optional Boolean Core Data attribute) as sectionNameKeyPath
. Even if values of flag
differ, performFetch:
leads to only one section titled @"1"
.