Validate textfield using Reactive Cocoa swift

615 views Asked by At

I am trying to validate UITextField if it has greater than 3 characters it should return true else return false. I tried using the below code but it is not working. What am I doing wrong?

 let validUserNameSignal = self.nameTextField.reactive.trigger(for: .valueChanged).observeValues {
        value in


    }.map { (value) in

        String(describing: value).characters.count > 3 ? true:false

    }
    print("user name valid result is \(validUserNameSignal)")
1

There are 1 answers

4
Charles Maria On BEST ANSWER

Here's how the code should look.

let validUserNameSignal =
        self.nameTextField
            .reactive
            .continuousTextValues
            .skipNil()
            .map { $0.characters.count > 3 }

validUserNameSignal.observeValues { value in
    print("user name valid result is \(value)")
}