Form validation by RxSwift with MVVM architecture
Form validation by RxSwift with MVVM architecture
pod 'RxCocoa'
pod 'RxSwift'
pod 'Action'
pod 'IQKeyboardManagerSwift'
- Download the project.
- Add necessary files in your project.
- Congratulations!
To run the example project, clone the repo, and run pod install from the Example directory first.
formViewModel.nameSubject <~> nameTextField.rx.text => rxbag // Two-way binding is donated by <~>
formViewModel.submitButtonEnabled ~> submitButton.rx.valid => rxbag // One-way binding is donated by ~>
submitButton.rx.bind(to: formViewModel.submitAction, input: ()) // action binding
formViewModel.submitAction.executionObservables.switchLatest()
.subscribe(onNext: { formData in
print(formData.parameters as Any)
UIAlertController.showAlert(title: "Form Validator", message: "Success")
}) => rxbag
formViewModel.formLoadingSubject.skip(1)
.subscribe(onNext: { [weak self] (isLoading) in
guard let self = self else {return}
self.view.endEditing(true)
if isLoading {
self.submitButton?.startAnimation()
} else {
self.submitButton?.stopAnimation()
}
}) => rxbagWe would love you for the contribution to FormValidation, check the LICENSE file for more info.
FormValidation is available under the MIT license. See the LICENSE file for more info.