Given this source code:
#include <Cocoa/Cocoa.h>
int main()
{
printf("%ldn%ldn",
[@"A 2" localizedStandardCompare:@"a 10"],
[@"A 2" localizedStandardCompare:@"a 10"]);
}
It produces two different results (presumably the first correct, the second incorrect):
$ clang++ ./cmp.m -o cmp -ObjC -framework Foundation && ./cmp
-1
1
This behaviour is consistent on two different machines (both MacOS 14), running two different versions of Xcode: 15 and 16. It doesn’t make any sense, but is consistent – after the first invocation of localizedStandardCompare
something breaks and then this methods always says that “A 2” is greater than “a 10” in natural ordering.
Addendum: on MacOS 10.15 / Xcode 12 it produces an expected result “-1 -1”.
Addendum2: this small repo runs this snippet on GitHub Actions: https://github.com/mikekazakov/localizedStandardCompare. It confirms the issue in MacOS14:
macos-12, xcode-14.2: -1 -1
macos-13, xcode-14.2: -1 -1
macos-12, xcode-13.1: -1 -1
macos-13, xcode-14.3.1: -1 -1
macos-14, xcode-16b6: -1 1
macos-14, xcode-15.4: -1 1
macos-14, xcode-14.3.1: -1 1
2