Inconsistent caseInsensitiveCompare behavior

(lldb) p [@"ΗΙzzz" caseInsensitiveCompare:@"ᾚabc"]
(long long) -1
(lldb) p [@"ᾚabc" caseInsensitiveCompare:@"ΗΙzzz"]
(long long) -1

Note the unicode char in the second string. The results can't be both -1, afaik, if one is -1 the other one should be +1.

This causes inconsistent indexing in a sorted array resulting in obscure crashes of my app.

Am I doing something wrong?

Tested on iOS 27 and macOS 26.6.

Tried switching to localizedCaseInsensitiveCompare, though that has similar issues

NSString *a = @"\u1F28\u0399abc"; // ἨΙabc
NSString *b = @"\u1F2E\u0399zzz"; // ἮΙzzz

[a localizedCaseInsensitiveCompare:b] == NSOrderedDescending; // YES
[b localizedCaseInsensitiveCompare:a] == NSOrderedDescending; // YES

NSString *c = @"\u0397\u0313\u0345abc"; // ᾘabc
NSString *d = @"\u1F28\u0399abc";       // ἨΙabc

[c localizedCaseInsensitiveCompare:d] == NSOrderedAscending; // YES
[d localizedCaseInsensitiveCompare:c] == NSOrderedSame;      // YES

Really getting confused here...

Feedback Assistant: FB24975737

Inconsistent caseInsensitiveCompare behavior
 
 
Q