I need to sort an array of dictionaries, using a keyed object from the dictionary. The object is an NSString that contains a float. I used an NSSortDescriptor but it sorts alphabetically. How would I make a custom selector or comparator to do it numerically?
Share
This should give you an idea of how this can be done using NSComparator blocks:
obj1andobj2are id pointers to a pair of dictionary objects in your array.Whatever you do within the NSComparator block is up to you. As long as you return either
NSOrderedSame,NSOrderedAscendingorNSOrderedDescending.In general you might be better advised using a real numeric data type (à la
[NSNumber numberWith...:x]) to hold such floating point values, than a string.