How to obtain an ordered list of coredata managed objects via accessing them via a relationship?
That is:
- have the following entities: LIST, LIST_ITEM (includes an ‘Order’ field), and ITEM.
- assume that I have already fetched the list I want to work with
- I can then use the coredata relationships to get the LIST_ITEMS via using the relationship: e.g. “list1.listItems”, and then for each of these LIST_ITEMS I can get the ITEM (“listItem1.item”)
But if I really just want, from the LIST, an ordered list of ITEMS from the list, based on the “Order” field in the LIST_ITEM, what is the easiest way of doing this?
You can sort the items returned by the relationship using an NSSortDescriptor just as you would in a regular fetch request. For example:
The key method here is
[NSSet sortedArrayUsingDescriptors:]