Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active April 7, 2018 14:39
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 laevandus/75920eb68b04a40df9dbe60e3540bc85 to your computer and use it in GitHub Desktop.
Save laevandus/75920eb68b04a40df9dbe60e3540bc85 to your computer and use it in GitHub Desktop.
final class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
let pantry = Pantry()
override func viewDidLoad() {
super.viewDidLoad()
// SignalProducer runs the closure immediately.
pantry.jams.producer.startWithValues { [weak self] (jams) in
self?.textView.text = jams.map({ $0.flavour.rawValue }).joined(separator: ", ")
}
// Signal runs the closure only when the property changes.
pantry.jams.signal.observeValues { (jams) in
print("Pantry has \(jams.count) jars of jam.")
}
pantry.add(jam: Jam(flavour: .orange))
}
@IBAction func addJam(_ sender: Any) {
pantry.add(jam: Jam(flavour: .apple))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment