Last active
August 29, 2015 14:04
-
-
Save aryaxt/89f7d7e589ba712c68ee to your computer and use it in GitHub Desktop.
Swift default if nil operator
This file contains hidden or 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 ||= {} | |
func ||= <T> (first: T?, second: T) -> T { | |
if let l = first { | |
return l | |
} | |
return second | |
} | |
// Usage | |
var possibleNilString: Stirng? | |
var myValue = possibleNilString ||= "Default Value if nil" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment