Created
February 10, 2015 17:17
-
-
Save ttepasse/5cce661a72633cee05a6 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
enum YesNo { | |
case Yes, No | |
} | |
class Foo { | |
var bar: YesNo? = .None { | |
didSet { | |
self.baz = calculateValueForBaz() | |
} | |
} | |
private func calculateValueForBaz() -> String { | |
switch (self.bar) { | |
case .Some(.Yes): | |
return "Ja" | |
case .Some(.No): | |
return "Nein" | |
default: | |
return "Möglich" | |
} | |
} | |
lazy var baz: String = { | |
self.calculateValueForBaz() | |
}() | |
} | |
let foo = Foo() | |
foo.bar // -> nil | |
foo.baz // -> "Möglich" | |
foo.bar = .Yes | |
foo.baz // -> "Ja" | |
foo.bar = .No | |
foo.baz // -> "Nein" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment