You don't need to abandon NSFetchedResultsController or NSOrderedSet. If you stick with NSOrderedSet, the easy way is to just add a method to your objects NSManagedObject subclass. So for instance, if you have an object Book with an ordered set of Chapters, you can add a method to the Chapters object:
- (NSUInteger)indexInBookChapters
{
NSUInteger index = [self.book.chapters indexOfObject:self];
return index;
}
Tip: Add this to a category so it doesn't get overwritten by CoreData auto generated code.
Then you can use this method in your sort descriptor for your NSFetchedResultsController:
fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"indexInBookChapters" ascending:YES]];
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…