given [URL.lastPathComponent] how do I sort as Finder sorts in macOS?
Example: urlPaths = contentsOfDirectory(at: ... e.g., ["1H", "10Ne", "11Na"] urlPaths.sort(by: { $0 < $1 } //Apple Swift version 5.9
print(urlPaths) // 10Ne 11Na 1H
whereas Finder filename sort gives // 1H 10Ne 11 Na
and is beautiful. I have always taken this sort for granted and am now buggered to duplicate it.
What you want is a “localized standard compare.” Here’s an example of using it via the SortComparator
protocol in the Swift REPL:
1> import Foundation
2> print(["1H", "10Ne", "11Na"].sorted())
["10Ne", "11Na", "1H"]
3> print(["1H", "10Ne", "11Na"].sorted(using: .localizedStandard))
["1H", "10Ne", "11Na"]