If I have an array of optional strings, and I want to sort it in ascending order with nils at the beginning, I can do it easily in a single line:
[\"b\", nil
Your example with Int gives a clue. If we had a max string value, we could plug that in.
Int
This works for strings that contain only alphabetic characters:
let maxString = "~" ["b", nil, "a"].sorted{ $0 ?? maxString < $1 ?? maxString }
Or simply:
["b", nil, "a"].sorted{ $0 ?? "~" < $1 ?? "~" }