Simple, easy and lightweight library for MVVM.
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...
- Xcode9.0+
- Swift4+
Add this to Podfile
pod "Closurable"
$ pod install
Add this to Cartfile
github "AcaiBowl/Closurable"
$ carthage update
ReactiveX/RxSwift [Lisense]
ReactiveKit/ReactiveKit [License]
Thank you.
Closurable is available under the MIT license. See the LICENSE file for more info.