Skip to content

Instantly share code, notes, and snippets.

@rectangular
Created December 21, 2017 22:59
Show Gist options
  • Save rectangular/fa09c0542b78814bbfd914729887bfa2 to your computer and use it in GitHub Desktop.
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
/**
??= 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
}
}
@rectangular
Copy link
Author

screenshot 2017-12-21 16 00 02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment