Hi All. Let's look at the code first: |
#import "stdafx.h" int main(int argc, const char *argv[]) { NSNumber *myFloat1; NSNumber *myFloat2; myFloat2 = [NSNumber numberWithDouble: 3.14]; myFloat2 = [NSNumber numberWithDouble: 2.78]; NSComparisonResult result; result = [myFloat1 compare: myFloat2]; if (result == NSOrderedSame) // acutal always NSLog(@"Numbers are equal"); else if (result == NSOrderedAscending) NSLog(@"Float1 is less than Float2"); else if (result == NSOrderedDescending) // expected! but not NSLog(@"Float1 is greater than Float2"); return 0; } | I found that there seems to be a problem with the compare method of NSNumber, in the code above, why is the comparison result of compare always NSOrderedSame, it should be NSOrderedDescending here isn't it ? Best regards!