ios - How to sort NSArray of custom objects by a specific property in descending order? -
how make piece of code order in descending order. code gives me array in ascending order:
nsarray *sortedproductsbystyle = [unsortedproducts sortedarrayusingcomparator: ^(product *p1, product *p2) { return [p1.productstyle compare:p2.productstyle options:nsnumericsearch]; }];
i thought using nsordereddescending work didn't:
nsarray *sortedproductsbystyle = [unsortedproducts sortedarrayusingcomparator: ^(product *p1, product *p2) { return [p1.productstyle compare:p2.productstyle options:nsnumericsearch | nsordereddescending]; }];
any ideas?
how inverting compare order?
nsarray *sortedproductsbystyle = [unsortedproducts sortedarrayusingcomparator: ^(product *p1, product *p2) { return [p2.productstyle compare:p1.productstyle options:nsnumericsearch]; }];
Comments
Post a Comment