I want to set the enabled
property of a UIButton
to true
iff there is at least one character in a UITextField
. How can this be achieved in Reactive Cocoa 4?
You can do it like this:
NSNotificationCenter.defaultCenter()
.rac_notifications(UITextFieldTextDidChangeNotification, object: textField)
.map { $0.object as! UITextField }
.map { $0.text }
.map { $0.isEmpty }
.startWithNext { button.enabled = !$0 }