Add Bind capabilities to Sejima library
- iOS 9.0+
- Xcode 9.0+
use CocoaPods with Podfile
pod 'RxSejima'
open your favorite terminal, go to your project root path:
pod install
use Carthage with Cartfile
github "MoveUpwards/RxSejima"
open your favorite terminal, go to your project root path and run:
carthage update
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)
}
}
}