I have an NSMutableDictionary
that contains keys that are NSString
s, and values that are objects of type "Fraction". This is a custom object that I have created and is exactly what it is, Fractions that are composed of a numerator, and a denominator (each one is an int). What I would like to do is get an array of the values (in this case, "Fraction" objects) from the NSMutableDictionary
, and then sort the array using @selector
as follows:
NSArray *myFractions = [myDict allValues];
NSArray *sortedFractions = [myFractions sortedArrayUsingSelector:@selector(comparator)];
or
NSArray *myFractions = [myDict allValues];
NSArray *sortedFractions = [myFractions sortedArrayUsingFunction:comparatorFunction context:nil];
My question is, how do I create a comparatorFunction method that will sort the "Fraction" objects in order of biggest, to smallest? Please remember that each "Fraction" object is composed of two variables: a numerator of type int, and a denominator that is also of type int.
This question is different from others that have been posted because here I am asking about how, within the "sortedArrayUsingFunction" method I am to sort the "Fraction" objects from greatest to least. The other questions that were thought to be duplicates were looking at sorting based on NSDate objects, or based on NSString values, whereas mine is different. As I said, I am very new to this, and needed something much more specific.
Thanks in advance.