RxSejima 0.10.2

RxSejima 0.10.2

Maintained by HubKit.



 
Depends on:
RxCocoa>= 0
RxSwift>= 0
Sejima>= 0
 

RxSejima 0.10.2

  • By
  • Damien NOËL DUBUISSON and Loïc GRIFFIÉ

Documentation Language: Swift 2, 3 and 4 Platform: iOS 11+ Carthage Compatible CocoaPods Codacy Badge Build Status License: MIT GitHub contributors Donate

RxSejima

Add Bind capabilities to Sejima library

Requirements

  • iOS 9.0+
  • Xcode 9.0+

Installation

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

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)
        }
    }
}