IOViewModel 0.1.4

IOViewModel 0.1.4

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Oct 2017
SwiftSwift Version 4.0
SPMSupports SPM

Maintained by Arnaud Dorgans.






Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

IOViewModel is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'IOViewModel'

Usage

Install XCTemplate and generate instantly beautiful viewmodels

ViewModel

import IOViewModel
import RxSwift
import RxSwiftExt

class UserViewModel: IOViewModel {

    typealias In = Input
    typealias Out = Output

    private (set) lazy var `in`: In = In(vm: self)
    private (set) lazy var out: Out = Out(vm: self)

    class Input: IOViewModelIn<UserViewModel> {

        lazy var user = BehaviorSubject<User?>(value: nil)
    }

    class Output: IOViewModelOut<UserViewModel> {

        var user: Observable<User> {
            return self.in.user.unwrap()
        }

        var name: Observable<String> {
            return user.map { $0.firstName + " " + $0.lastName }
        }
    }
}

ViewController

let vm = UserViewModel()

userView.rx.user
    .bind(to: vm.in.user)
    .disposed(by: disposeBag)

vm.out.name
    .bind(to: nameLabel.rx.text)
    .disposed(by: disposeBag)

XCTemplate

IOViewModel is published with xctemplate.

To install it, just go in xctemplates directory and run this command in a terminal:

sh install.sh

Author

Arnoymous, [email protected]

License

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