Costello Costello - 7 months ago 78
Swift Question

Validate textfield using Reactive Cocoa swift

I am trying to validate

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)")


Here's how the code should look.

let validUserNameSignal =
            .map { $0.characters.count > 3 }

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