I'm using a for loop to create a string of a dicts keys and values. Unfortunately swift behaves differently on Mac and Linux.
for key in parameters.keys.sorted() {...}
I want to sort my keys by byte value, not alphabetically, lowercase parameters should be listed after uppercase ones.
So a key like "AWT" should come before a key like "Ast".
On Apple platforms, Swift strings comparison is a lexicographical comparison of Unicode scalar values, based on the so-called "Unicode Normalization Form D", see How String Comparison happens in Swift or What does it mean that string and character comparisons in Swift are not locale-sensitive? for details.
On Linux, the sort order is different. That is a known problem ([String] sort order varies on Darwin vs. Linux) and should be fixed in Swift 4.
If you only care about ASCII characters then a possible approach would be to compare the UTF-8 representation of the strings:
This gives identical results on Apple platforms and on Linux.
But note that this is not the default sort order for Swift Strings on Apple platforms. To replicate that on Linux (before it is fixed in Swift 4), the following algorithm would work: