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

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -