开发者

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

Ross


It 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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜