I have a complex core data mapping in my app, simplified to the relevant pats to this question here in this image:
My question is how to get sorted Foo's efficiently. Let's say that in one of my views, I have a sectioned table with every foo in it. The sections are the categories. Each section of foo (in a category) has an ordering.
Now, I am fetching them using this algorithm:
- Fetch a list of all categories, sorted by name
- For each category, fetch the Sorted Foos, sorted by index ascending
- For each SortedFoo, fetch the associated Foo, stick in an array
- Take the Foos, now sorted by index in an array, and add this array to a 2D array
- Return the 2D array as the ordered foo's in each alphabetized category.
This seems soooooo inefficient to me. Surely there must be a better way to do this common type of fetch. Can anybody suggest a new way to do this?