Costello Costello - 1 year ago 174
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)")

Answer Source

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)")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download