Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort the results of an NSFetchedResultsController using the order of an NSOrderedSet

NSOrderedSets save the order of the objects in the table. If you access an NSManagedObject subclass instance with a property that is an NSOrderedSet, then they will be in order.

However, there is seemingly no way to access that order using an NSSortDescriptor when creating an NSFetchRequest.

It appears from the raw SQLite DB, that order is stored in fields named Z_FOK_<relationship name>. The data is available, but it doesn't appear to be visible through the core data APIs.

Does anyone know a way to write an NSSortDescriptor that will work with a SQLite DB to return the results in the order specified by the NSOrderedSet?


Update

Related Question: NSFetchedResultsController and NSOrderedSet relationships

like image 692
Corey Floyd Avatar asked Jul 29 '13 18:07

Corey Floyd


1 Answers

I don't think that is possible. The "ordering" is associated with the to-many relationship from one entity A to another entity B, it is not a property of the target entity B. But a sort descriptor for a Core Data fetch request can only use (persistent) properties of the entity.

like image 53
Martin R Avatar answered Oct 19 '22 14:10

Martin R