0
votes

I am fetching the details of some products and grouping it under sections based on the main category.

Product object has two attributes mainCategory and subCategory.

I use feched results controller to group all products using mainCategory. Now with in the main category, there are products present from different subcategories. I want to group those products together, is it possible to group objects with in a section?

Below is what I am looking for, table will look like

MainCategory 1
---ProductA.Subcategory1
---ProductB.Subcategory1
---ProductC.Subcategory1
---ProductD.Subcategory2
---ProductE.Subcategory2
MainCategory 2
---ProductF.Subcategory1
---ProductG.Subcategory1
---ProductH.Subcategory1
---ProductI.Subcategory2
---ProductJ.Subcategory2

Is this achievable? Is there a way to use setPropertiesToGroupBy or something?

1

1 Answers

1
votes

You can achieve this with sort descriptors of NSFetchRequest.

request.sortDescriptors = @[
    [NSSortDescriptor sortDescriptorWithKey:@"mainCategory" ascending:YES],
    [NSSortDescriptor sortDescriptorWithKey:@"subCategory" ascending:YES],
];