Skip to content

Instantly share code, notes, and snippets.

@Sajjon
Created September 9, 2018 20:33
Show Gist options
  • Save Sajjon/3c1287dc40eb2224ad81f56d25e9ce92 to your computer and use it in GitHub Desktop.
Save Sajjon/3c1287dc40eb2224ad81f56d25e9ce92 to your computer and use it in GitHub Desktop.
Typeerasure for AnyNavigator
struct AnyNavigator<Destination_>: Navigator {
typealias Destination = Destination_
private let _navigateTo: (Destination_) -> Void
private let _start: () -> Void
init<Concrete>(_ concrete: Concrete) where Concrete: Navigator, Concrete.Destination == Destination_ {
_navigateTo = concrete.navigate
_start = concrete.start
}
// MARK: - Navigator methods
func navigate(to destination: Destination) {
_navigateTo(destination)
}
func start() {
_start()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment