-
-
Save vojto/7ddbb2ce545414469d49d4dfccc6a8e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RectangleConfig { | |
var width: MutableProperty<Int>(value: 0) | |
var height: MutableProperty<Int>(value: 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.flatMap(.latest) { maybeConfig -> SignalProducer<Int?, NoError> in | |
if let config = maybeConfig { | |
return config.width.producer | |
} else { | |
return SignalProducer<Int?, NoError>(value: nil) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment