What is NSComparisonResult
and NSComparator
?
I\'ve seen one of the type definitions, something like that:
typedef NSComparisonR
NSComparisonResult comparisionresult;
NSString * alphabet1;
NSString * alphabet2;
// Case 1
alphabet1 = @"a";
alphabet2 = @"A";
comparisionresult = [alphabet1 caseInsensitiveCompare:alphabet2];
if (comparisionresult == NSOrderedSame)
NSLog(@"a and a are same. And the NSComparisionResult Value is %ld \n\n", comparisionresult);
//Result: a and a are same. And the NSComparisionResult Value is 0
// Case 2
alphabet1 = @"a";
alphabet2 = @"B";
comparisionresult = [alphabet1 caseInsensitiveCompare:alphabet2];
if (comparisionresult == NSOrderedAscending)
NSLog(@"a is greater than b. And the NSComparisionResult Value is %ld \n\n", comparisionresult);
//Result: a is greater than b. And the NSComparisionResult Value is -1
// Case 3
alphabet1 = @"B";
alphabet2 = @"a";
comparisionresult = [alphabet1 caseInsensitiveCompare:alphabet2];
if (comparisionresult == NSOrderedDescending)
NSLog(@"b is less than a. And the NSComparisionResult Value is %ld", comparisionresult);
//Result: b is less than a. And the NSComparisionResult Value is 1