Skip to content

Instantly share code, notes, and snippets.

@ohetzendorfer
Created April 6, 2017 19:41
Show Gist options
  • Save ohetzendorfer/d50195bb73d72ab2356be7c81bf86c27 to your computer and use it in GitHub Desktop.
Save ohetzendorfer/d50195bb73d72ab2356be7c81bf86c27 to your computer and use it in GitHub Desktop.
Array sort with enum
//: Playground - noun: a place where people can play
import UIKit
enum Type {
case one, two, three
var order: Int {
switch self {
case .one: return 1
case .two: return 2
case .three: return 3
}
}
}
struct Object {
var type: Type
init(type: Type) {
self.type = type
}
}
var objects = [Object]()
objects.append(Object(type: .two))
objects.append(Object(type: .three))
objects.append(Object(type: .one))
objects.sort {
return $0.type.order < $1.type.order
}
for object in objects {
print("Object: \(object)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment