Skip to content

Instantly share code, notes, and snippets.

@t-kashima
Created May 14, 2015 14:19
Show Gist options
  • Save t-kashima/f53d07d7585b050c4b12 to your computer and use it in GitHub Desktop.
Save t-kashima/f53d07d7585b050c4b12 to your computer and use it in GitHub Desktop.
ReactiveCocoa for swift
import UIKit
import ReactiveCocoa
class ViewController: UIViewController {
@IBOutlet var textInput: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var textSignal = self.textInput.rac_textSignal()
textSignal.map {
(text: AnyObject!) -> AnyObject! in
var textString = text as! NSString
if 3 >= textString.length {
return UIColor.lightGrayColor()
}
return UIColor.whiteColor()
}
.setKeyPath("backgroundColor", onObject: self.textInput)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment