Created
January 29, 2020 13:00
-
-
Save popmedic/92736fcc45c35f92c926845547af8925 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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