I want to solve this error. "Cannot convert value of type 'SharedSequence<DriverSharingStrategy, ControlProperty<String?>.Element>' (aka 'SharedSequence<DriverSharingStrategy, Optional>') to expected argument type 'Driver' (aka 'SharedSequence<DriverSharingStrategy, String>')" And "Cannot convert value of type 'SharedSequence<DriverSharingStrategy, Data?>' to expected argument type 'Driver' (aka 'SharedSequence<DriverSharingStrategy, String>')"
But I don't know how to fix this error. I don't think something fits with the viewModel, but I don't know what it is. The place where the error occurs is the asDriver. I am using RxSwift and MVVM patterns.
func bindViewModel() {
let api = ProfileAPI()
let input = ModifyProfileViewModel.input(nickName: nickNameTxtField.rx.text.asDriver(onErrorJustReturn: nil), userImage: image.asDriver(), doneTap: saveBtn.rx.tap.asSignal())
let output = viewModel.transform(input)
output.result.emit(onCompleted: { self.navigationController?.popViewController(animated: true)}
).disposed(by: rx.disposeBag)
}
This is my ViewController code
class ModifyProfileViewModel: ViewModelType {
let disposeBag = DisposeBag()
struct input {
let nickName: Driver<String>
let userImage: Driver<String>
let doneTap: Signal<Void>
}
struct output {
let result: Signal<String>
let isEnabled: Driver<Bool>
}
func transform(_ input: input) -> output {
let api = ProfileAPI()
let result = PublishSubject<String>()
let info = Driver.combineLatest(input.nickName, input.userImage)
let isEnabled = info.map { !$0.0.isEmpty }
input.doneTap.withLatestFrom(info).asObservable().subscribe(onNext: { nickName, image in
api.putModifyProfile().subscribe(onNext: { (response, statusCode) in
switch statusCode {
case .success:
result.onCompleted()
case .noHere:
result.onNext("fail")
default:
result.onNext("default")
}
}).disposed(by: self.disposeBag)
}).disposed(by: disposeBag)
return output(result: result.asSignal(onErrorJustReturn: ""), isEnabled: isEnabled.asDriver())
}
}
And this is my ViewModel code What is the problem?