Created
December 21, 2017 22:59
-
-
Save rectangular/fa09c0542b78814bbfd914729887bfa2 to your computer and use it in GitHub Desktop.
??= An operator that will assign the left hand value to the right hand value if the left hand value is nil
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
/** | |
??= An operator that will assign the left hand value | |
to the right hand value if the left hand value is nil | |
Example Usage: | |
``` | |
var str: String? | |
str ??= "Bob" | |
print(str!) | |
``` | |
- TODO: Define a precedence group | |
*/ | |
import UIKit | |
infix operator ??= | |
func ??=(lhs: inout String?, rhs: String) { | |
if lhs == nil { | |
lhs = rhs | |
} | |
} |
Author
rectangular
commented
Dec 21, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment