NSOrderedDescending instead of NSOrderedSame for equal strings, why?
I'm compairing two strings. There are equal. isEqualToString:
returns NSOrderedDescending
.
I thought isEqualToString:
would return NSOrderedSame
. Can someone explain to me why this happens?
example case...
NSString *myString = @"1";
if ( [myString isEqualToString:@"1"] == NSOrderedSame ) {
// is NSOrderedSame
}
Since writing the question I know I should use instead compare:
. It will return NSOrderedSame
. But I w开发者_运维问答ould like to know, still, why this happens.
Thanks
RossIt doesn't return NSOrderedDescending
, it returns YES
. Check the return type of that method!
- (BOOL)isEqualToString:(NSString *)aString
NSOrderedDescending
is an NSComparisonResult
, and happens to have a value of 1
due to its declaration:
enum {
NSOrderedAscending = -1,
NSOrderedSame,
NSOrderedDescending
};
typedef NSInteger NSComparisonResult;
Don't mix and match types!
精彩评论