(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.
Thanks for the background info.
With this code I cannot reproduce the inconsistencies anymore
Cool.
While playing around with this I also noticed that normalising the strings (using -decomposedStringWithCanonicalMapping) also improved things. However, I only did limited testing, so it’s possible that it only works in the specific cases you highlighted.
Still, the normalisation test is useful because, by definition, Foundation’s locale-aware APIs (like -localizedStandardCompare:, which is my go-to tool for this sort of thing) are supposed to be normalisation-insensitive. So if normalisation changes things then that it’s clearly Foundation’s bug to fix.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"