Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bigMOTOR/80fa4a0753075296f6f44454189795a1 to your computer and use it in GitHub Desktop.
Save bigMOTOR/80fa4a0753075296f6f44454189795a1 to your computer and use it in GitHub Desktop.
2020-12-20_Article_SwiftUInCleanArchitecture_3
protocol ModelledView: View {
associatedtype ViewModel: ObservableObject
var viewModel: ViewModel { get }
init(model: ViewModel)
}
struct ModelledViewFactory<T: ModelledView> {
@Environment(\.diContainer) private var diContainer: DIContainer
func build(_ builder: (DIContainer)->T.ViewModel) -> T {
let viewModel = builder(diContainer)
return T(model: viewModel)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment