Created
August 2, 2016 15:34
-
-
Save giginet/ab3c800087fe0f42af1dfb5a2c0b4dae to your computer and use it in GitHub Desktop.
||= operator in Swift
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 left precedence 150 } | |
public func ||= <T>(lhs: inout T?, rhs: T?) { | |
if lhs == nil { lhs = rhs } | |
} | |
var a: Int? = nil | |
a ||= 10 | |
print(a) | |
var b: Int? = 20 | |
b ||= 10 | |
print(b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment