Last active
May 12, 2020 06:01
-
-
Save momamene/bb5ac5a7a0d56a00766cfed2be3e9b96 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // SampleView.swift | |
| // Usage: | |
| // UIHostingController(rootView: SampleView(viewModel: viewModel)) | |
| struct SampleView: View { | |
| private let viewModel: SampleViewModelType | |
| private let disposeBag = DisposeBag() | |
| init(viewModel: SampleViewModelType) { | |
| self.viewModel = viewModel | |
| bindViewModel() | |
| } | |
| func bindViewModel() { | |
| viewModel.outputs.title | |
| .drive(onNext: { self.title = $0 }) | |
| .disposed(by: disposeBag) | |
| } | |
| @State var title: String = "Default title" { | |
| didSet { print("title did set: \(title)") } | |
| } | |
| var body: some View { | |
| Button(action: viewModel.inputs.buttonTapped) { | |
| Text(title) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment