I have a class (from NSObject ) that contains:
NSString name int position float speed
Then I create an array ( NSMutableArray ) of objects from this class. Then I would like to sort the array by the speed value, which is a float .
I initially had float as NSNumber and int as NSInteger , and I successfully sorted with:
[myMutableArray sortUsingFunction:compareSelector context:@selector(position)]
where myMutableArray is my array of objects.
here is the function:
static int compareSelector(id p1, id p2, void *context) { SEL methodSelector = (SEL)context; id value1 = [p1 performSelector:methodSelector]; id value2 = [p2 performSelector:methodSelector]; return [value1 compare:value2]; }
Now when I use int instead of NSInteger , the above code does not work. Is there a lower level command that I should use to do sorting? Thanks!
source share