Skip to content

Instantly share code, notes, and snippets.

@momamene
Created May 6, 2020 11:07
Show Gist options
  • Select an option

  • Save momamene/0b9d06dbbf4fc52613bf6ccebc768199 to your computer and use it in GitHub Desktop.

Select an option

Save momamene/0b9d06dbbf4fc52613bf6ccebc768199 to your computer and use it in GitHub Desktop.
struct SampleView_General: View {
@ObservedObject private var viewModel: ObservableSampleViewModel
init(viewModel: SampleViewModelType) {
self.viewModel = .init(viewModel)
}
var body: some View {
Button(action: viewModel.inputs.buttonTapped) {
Text(viewModel.outputs.title)
}
}
}
private typealias ObservableSampleViewModel = ObservableViewModel<SampleViewModelInputs, SampleViewModelOutputs>
extension ObservableSampleViewModel {
convenience init(_ viewModel: SampleViewModelType) {
self.init(inputs: viewModel.inputs, outputs: viewModel.outputs)
outputs.bind(\\.title, value: "initial value")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment