You could do this with an enum.
enum Status: Int {
case new = 1
case open = 2
case closed = 3
case unknown = 99
init(string: String) {
switch string {
case "new", "New": self = .new
case "open", "Open": self = .open
case "closed", "Closed": self = .closed
default:
self = .unknown
}
}
}
To use the enum, you could initialize like this:
var myStatus = Status(string: object["status"])
And use it like this:
print(myStatus) // prints "new"
print(myStatus.rawValue) // prints "1"
Edit: Since the enum has an underlying type of Int, to accomplish your sort you can compare the resulting Status directly (Thanks to this question https://stackoverflow.com/a/27871946/1718685):
var sortedOrders = orders.sort { Status(string: $0["status"]) < Status(string: $1["status"]) }