Skip to content

trsxxii/Closurable

Repository files navigation

Closurable

Simple, easy and lightweight library for MVVM.

Language Platform License Version carthage compatible

Usage

import Closurable

final class ViewController: UIViewController {
    @IBOutlet fileprivate weak var button: UIButton!
    @IBOutlet fileprivate weak var buttonLabel: UILabel!
    
    fileprivate let viewModel = ViewModel()
    fileprivate let bag = ReleaseBag()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // linking
        button.onTap { [unowned self] _ in
            self.viewModel.updateButtonTapCount()
        }.released(by: bag)
        
        // binding
        viewModel.subscribe(\.buttonTapCount) { [unowned self] (viewModel, _) in
            self.buttonLabel.text = "\(viewModel.buttonTapCount)"
        }.released(by: bag)
    }
}

final class ViewModel: NSObject {
    @objc dynamic private(set) var buttonTapCount: Int = 0
    
    func updateButtonTapCount() {
        buttonTapCount += 1
    }
}

and more...

Requirements

  • Xcode9.0+
  • Swift4+

Installation

Add this to Podfile

pod "Closurable"
$ pod install

Add this to Cartfile

github "AcaiBowl/Closurable"
$ carthage update

References

ReactiveX/RxSwift [Lisense]
ReactiveKit/ReactiveKit [License]

Thank you.

License

Closurable is available under the MIT license. See the LICENSE file for more info.