Search code examples
cocoacomparisonnsstringmacos-carboncfstring

What NSString compare method call is equivalent to a CFStringCompare function call?


I am converting some old carbon code to Cocoa and need to use a comparison function that will return the same result as the one in carbon.

I am calling:

CFStringCompare( stringA, stringB, kCFCompareCaseInsensitive | kCFCompareDiacriticInsensitive | kCFCompareNumerically );

Now, if stringA & stringB were NSString's and I wanted to compare them using a NSString method, which one, with what options (if any), would return the same result as the CFStringCompare function above?


Solution

  • The answer appears to be:

    NSStringCompareOptions  compareOptions = NSCaseInsensitiveSearch | NSNumericSearch | NSDiacriticInsensitiveSearch;
    
    result = [stringA compare:stringB options:compareOptions];