So i have an array that i retrieve from a web service in no particular order
example:
0 => x large,
1 => large,
2 => XX large,
3 => small,
4 => medium,
5 => x small
I need to sort them: firstly based on specific – which could be reverse alphabetic:
small
medium
large
Secondly i need to sort them based on their ‘x’ counter parts:
x small
small
medium
large
x large
xx large
I know i can do this with brute force string matching but i would really like a suggestion on how to do this tidily, perhaps a regex or something more elegant?
Use NSComparator block syntax. Something like
In the second approach I added a mapping between the numbers send by the web server and the x-sizes. Now
[obj size];is suppose to return a NSNumber object.The second task of the question — the grouping into small, medium, large — could be done like this: