简体   繁体   中英

structure viewModel for RxSwift

I'm learning MVVM and RxSwift and I want to bind all the object from the UI. I try to create a viewModel but the compiler pop up an error, am I create the view model wrong? this is my code and UI I want to bind.

环境

Cannot use instance member 'BasicInfoViewModel' within property initializer; property initializers run before 'self' is available

    struct BasicInfoViewModel {

    let infos = PublishSubject<InfoResult>()

    let selectedImage: Observable<UIImage>
    let fullname: Observable<String>
    let phoneNumber: Observable<String>
    let email: Observable<String>
    let placeOfBirth: Observable<String>
    let dateOfBirth: Observable<String>
    let religion: Observable<String>

    var isValid: Observable<Bool> {
        return Observable.combineLatest(fullname.asObservable(), phoneNumber.asObservable(), email.asObservable(), placeOfBirth.asObservable(), dateOfBirth.asObservable(), religion.asObservable()).map { $0.0.count > 0 }
    }
}

    class BasicInfoViewController: UITableViewController {

        var viewModel = BasicInfoViewModel()
    }

您需要在视图中构建您的 BasicInfoViewModel 加载方法并从视图中传递输入。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM