Skip to content

Instantly share code, notes, and snippets.

@soxjke
Forked from vojto/picking.swift
Last active March 10, 2017 10:46
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 soxjke/1659a9cec8eb1d03992dcf6df22756cf to your computer and use it in GitHub Desktop.
Save soxjke/1659a9cec8eb1d03992dcf6df22756cf to your computer and use it in GitHub Desktop.
struct RectangleConfig {
var width: Int = 0
var height: Int = 0
}
class ConfigView: NSView {
// Models
let config = MutableProperty<RectangleConfig?>(nil)
var width: SignalProducer<Int?, NoError>!
func awakeFromNib() {
// Extract config.width to self.width
// self.width should change when config.width changes, or when
// config changes
// self.width is Optional<Int> because config is Optional<RectangleConfig>
// and so if there is no config, then there is no width
self.width = config.producer.map { $0?.width }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment