RxSejima
Add Bind capabilities to Sejima library
Requirements
- iOS 9.0+
- Xcode 9.0+
Installation
CocoaPods with Podfile
usepod 'RxSejima'
open your favorite terminal, go to your project root path:
pod install
Carthage with Cartfile
usegithub "MoveUpwards/RxSejima"
open your favorite terminal, go to your project root path and run:
carthage update
Usage
Create a basic view controller with a MUButton
import Sejima
import RxSejima
class ViewController: UIViewController {
@IBOutlet private var button: MUButton!
private let bag = DisposeBag()
private let viewModel: ViewControllerViewModel()
override func viewDidLoad() {
super.viewDidLoad()
viewModel.loading.bind(to: button.rx.loading).disposed(by: bag)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
startLoading()
}
}
Add your view model with the logic.
import RxSwift
class ViewControllerViewModel {
internal let loading = BehaviorSubject<Bool>(value: false)
internal func startLoading() {
loading.onNext(true)
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { [weak self] in
self?.loading.onNext(false)
}
}
}