Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is purpose of using NSOrderedSame? [duplicate]

Tags:

objective-c

Possible Duplicate:
Is there a difference between NSString compare: and isEqual(ToString):?

What is the purpose of using NSOrderedSame in the below line of code?

if([result caseInsensitiveCompare:@"ERROR"]==NSOrderedSame)

where result is a string variable.

like image 992
Shankaranarayana Avatar asked Aug 09 '11 07:08

Shankaranarayana


1 Answers

The compare methods in Cocoa and Cocoa Touch return how the compared objects should be ordered, instead of just returning a boolean that tells whether the values are the same or not. There are three values:

  • NSOrderedAscending: The left operand is smaller than the right operand.
  • NSOrderedSame: The two operands are equal.
  • NSOrderedDescending: The left operand is greater than the right operand.

So your code simply checks whether the string pointed to by result is equal to the string "ERROR", ignoring differences in case (that is, "error", "eRRoR" etc. are all considered to be equal to "ERROR").

like image 178
DarkDust Avatar answered Sep 23 '22 08:09

DarkDust