views:

22

answers:

1

I would like to use BWOrderedManagedObject to store an array of ordered objects in Core Data, using NSFetchedResultsController for displaying the data.

However, all of BWOrderedManagedObject's methods seem to simply return an array of ordered objects; NSFetchedResultsController requires an NSFetchRequest, and the only way to sort an NSFetchRequest is to provide an array of NSSortDescriptors.

So, I'm a bit stuck here as to how to use BWOrderedManagedObject with NSFetchedResultsController—does anyone know how I might be able to successfully do this?

(I could probably create my own ordering key and use this with the sort descriptors, but I'm assuming that BWOrderedManagedObject would be more robust...?)

+2  A: 

NSFetchedResultsController expects to be fetching information from unordered sets and returning arrays. That is why it wants a sort descriptor. It has to convert the unordered set into an array and it needs the sort to do that.

I think it would easiest to implement your own ordering. I use a relationship to an "Ordering" entity that is nothing but an index attribute and a relationship to the ordered entity. Then all you have to do is sort and fetch the Ordering objects and then walk their individual relationships to find the target objects in order. It's fast, clean, flexible and works with NSFetchedResultsController.

TechZen
Yes, I realise that the `NSFetchedResultsController` is expecting an unordered set—I was wondering whether there was a way to get the sort descriptors to use the `BWOrderedManagedObject` ordering or whether it was possible to pass an array to `NSFetchedResultsController`.However, I think you're right that implementing my own ordering will be easier. Thanks!
Steve Harrison
I haven't fiddled BWOrderedManagedObject much but I don't think the FRC can use an attribute that is itself an array as the section attribute. Plus, you have the whole objectID/URI info to process.
TechZen