Skip to content

Instantly share code, notes, and snippets.

@macbellingrath
Created January 12, 2016 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macbellingrath/4e955b260b3cf1de5cf9 to your computer and use it in GitHub Desktop.
Save macbellingrath/4e955b260b3cf1de5cf9 to your computer and use it in GitHub Desktop.
Comparing ReactiveCocoa with RxSwift
/* RAC*/
let userNameStrings = userNameTextfield
.rac_textSignal()
.toSignalProducer()
.map { text in text as! String }
let passwordStrings = passwordTextfield.rac_textSignal()
.toSignalProducer()
.map { password in password as! String }
let signal = zip(userNameStrings, passwordStrings)
signal.startWithNext { (un, pw) in self.submitButton.enabled = (un.characters.count > 0) && (pw.characters.count > 0) }
//Or ?
userNameTextfield.rac_textSignal()
.subscribeNext { _ in self.userNameTextfield.backgroundColor = self.userNameTextfield.validate() }
passwordTextfield.rac_textSignal()
.subscribeNext { _ in self.passwordTextfield.backgroundColor = self.passwordTextfield.validate() }
/*RxSwift */
nameTextField.rx_text
.map{ "Hello " + $0 }
.throttle(0.5, scheduler: MainScheduler.instance)
.subscribeNext { self.greetingLabel.text = $0 }
.addDisposableTo(disposebag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment