Skip to content

Instantly share code, notes, and snippets.

@popmedic
Created January 29, 2020 13:00
Show Gist options
  • Save popmedic/92736fcc45c35f92c926845547af8925 to your computer and use it in GitHub Desktop.
Save popmedic/92736fcc45c35f92c926845547af8925 to your computer and use it in GitHub Desktop.
import UIKit
protocol Invokable {
var order: Int { get }
func invoke()
}
class A: Invokable {
var order = 0
func invoke() { print("A") }
}
class B {}
class C: Invokable {
var order = 1
func invoke() { print("C") }
}
class D {}
var registry: [String: Any] = ["A": A(), "B": B(), "C": C(), "D": D()]
registry.filter { $0.value is Invokable }
.sorted { ($0.value as! Invokable).order < ($1.value as! Invokable).order}
.forEach { ($0.value as! Invokable).invoke() }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment