Skip to content

Instantly share code, notes, and snippets.

@IsaAliev
Last active October 17, 2020 08:37
Show Gist options
  • Save IsaAliev/d7251e46e0b57e375412e7c5e5dee29f to your computer and use it in GitHub Desktop.
Save IsaAliev/d7251e46e0b57e375412e7c5e5dee29f to your computer and use it in GitHub Desktop.
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