Skip to content

Instantly share code, notes, and snippets.

@prat14k
Created November 21, 2019 09:46
Show Gist options
  • Save prat14k/9e7ed14c6f594ab5c5faddf3eb17f97e to your computer and use it in GitHub Desktop.
Save prat14k/9e7ed14c6f594ab5c5faddf3eb17f97e to your computer and use it in GitHub Desktop.
Playing with sort method of Swift
enum EN: Int, CaseIterable {
case a, b, c, d, e, f, j, k
var sis: Bool {
switch self {
case .a, .b, .d, .f, .j, .k: return true
default: return false
}
}
}
let allCases = [EN.b, .f, .a, .e, .j, .c, .d, .k]
let vv = allCases.sorted(by: { ($0.sis && !$1.sis) || (($0.sis == $1.sis) && ($0.rawValue < $1.rawValue)) })
print(vv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment