Created
September 29, 2020 23:06
-
-
Save nalexn/3014b5d6b8609f1e8a68eee83a394796 to your computer and use it in GitHub Desktop.
Article_009 https://nalexn.github.io/uikit-switfui/
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
class HomeViewModel: ObservableObject { | |
@Published var isLoadingData = false | |
func doSomething() { ... } | |
} | |
class HomeViewController: UIViewController { | |
let loadingIndicator: UIActivityIndicatorView! | |
let viewModel = HomeViewModel() | |
let disposeBag = DisposeBag() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
viewModel | |
.$isLoadingData // obtaining Publisher | |
.asObservable() // converting to Observable | |
.bind(to: loadingIndicator.rx.isAnimating) // RxCocoa binding | |
.disposed(by: disposeBag) | |
} | |
@IBAction func handleButtonPressed() { | |
viewModel.doSomething() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment