Created
December 20, 2017 14:10
-
-
Save norman784/a224f1c83382e8eeddc0f76ccf17b52f to your computer and use it in GitHub Desktop.
Lazy way to initialize a class without having multiple constructors (only works with mutable vars)
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 Demo { | |
var foo: String? = nil | |
var bar: String? = nil | |
init(block: (Demo) -> Void) { | |
block(self) | |
} | |
} | |
Demo { | |
$0.foo = "bar" | |
} | |
Demo { | |
$0.bar = "foo" | |
} | |
Demo { | |
$0.foo = "bar" | |
$0.bar = "foo" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment