I have an array of a dictionary that it sortedArrayUsingComparator sorts them based on the key;
listPerc = [listItem sortedArrayUsingComparator: ^(id a, id b) {
NSString *first = [a objectForKey:@"perc"];
NSString *second = [b objectForKey:@"perc"];
return [first compare:second];
the problem is that this key is a numbers, and order is so for example: 1,10, 15, 17, 2, 23, etc.
it does not calculate the magnitude of the number.
how can I do?
Make them into NSNumber objects and compare those instead. Either store them as NSNumbers to start with (preferred method) or convert them when comparing (slower).
Converting an NSString to an NSNumber can be done with: