Created
February 2, 2016 08:29
-
-
Save ninjazoete/b5982d81fcf9855f211f to your computer and use it in GitHub Desktop.
Handle to generic protocol conforming type
This file contains 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
protocol PresentationItem { } | |
protocol AnyPresenter { | |
func _present(item: Any) -> Void | |
} | |
protocol Presenter: AnyPresenter { | |
typealias PresentationType | |
func present(item: PresentationType) -> Void | |
} | |
extension Presenter { | |
func _present(state: Any) -> Void { | |
if let typed = state as? PresentationType { | |
present(typed) | |
} | |
} | |
} | |
struct UserPresentationItem : PresentationItem { } | |
class View : Presenter { | |
func present(item: UserPresentationItem) { | |
// Use item... | |
} | |
} | |
let presenter = View() | |
let anyPresenter: AnyPresenter = presenter | |
anyPresenter._present(UserPresentationItem()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment