You want to use lexicographic comparison, that is, if the first fields are equal, compare the second field, otherwise compare the first fields.
, , , , == < .
let result = items.sorted {
switch ($0["category"],$1["category"]) {
// if neither "category" is nil and contents are equal,
case let (lhs,rhs) where lhs == rhs:
// compare "status" (> because DESC order)
return $0["status"] > $1["status"]
// else just compare "category" using <
case let (lhs, rhs):
return lhs < rhs
}
}
a lexicographicCompare, , , a) , <, Comparable, nils b) .