Last active
October 17, 2020 08:37
-
-
Save IsaAliev/d7251e46e0b57e375412e7c5e5dee29f to your computer and use it in GitHub Desktop.
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 ViewRepresentable: ViewModelTypeErasedViewRepresentable { | |
associatedtype ViewModelType: ViewModel | |
var model: ViewModelType! { get set } | |
func bindWithModel() | |
} | |
protocol ViewModelTypeErasedViewRepresentable: class { | |
var typeErasedViewModel: ViewModel? { get set } | |
} | |
extension ViewRepresentable { | |
var typeErasedViewModel: ViewModel? { | |
get { model } | |
set { model = (newValue as! Self.ViewModelType) } | |
} | |
} | |
extension ViewRepresentable { | |
func setupViewModel() { | |
model?.setup() | |
bindWithModel() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment