Last active
February 29, 2016 13:29
-
-
Save radex/68de9340b0da61d43e60 to your computer and use it in GitHub Desktop.
Optional assignment operator implementation. `foo ??= bar` will evaluate and assign bar to foo if and only if foo is nil. Equivalent to `||=` in Ruby and other languages.
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
infix operator ??= { | |
associativity right | |
precedence 90 | |
assignment | |
} | |
func ??= <T>(inout variable: T?, expr: @autoclosure () -> T) { | |
if variable == nil { | |
variable = expr() | |
} | |
} |
Why isn't this change merged into the SwiftyUserDefaults project?
@semireg Because it's not User Defaults-specific, and although I like this operator, I don't want to add it to everyone's code in an unrelated project.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why isn't this change merged into the SwiftyUserDefaults project?