I am allowing users to be able to sort either by price (int) or by distance (float).
I have an NSMutableArray of NSdictionary objects that store the data as follows:
({"asking_price" = 588832;
distance = "2.0250673476224";
id = 510cc41cc7e24c6c6d000000;
"number_of_bathrooms" = 2; )}
my sort function is as follows:
+(void) sort:(NSMutableArray *)classifieds:(NSString *)key:(Boolean)isAscending
{
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:key ascending:isAscending];
[classifieds sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
}
My question is considering distance is a string in the dictionary and price is an int, how can I modify my function to actually do sorting it in floats when I pass in key of “distance” and in ints when I pass in a key of “asking_price”
Thanks in advance
1 Answer