Skip to content

Instantly share code, notes, and snippets.

@aryaxt
Last active August 29, 2015 14:04
Show Gist options
  • Save aryaxt/89f7d7e589ba712c68ee to your computer and use it in GitHub Desktop.
Save aryaxt/89f7d7e589ba712c68ee to your computer and use it in GitHub Desktop.
Swift default if nil operator
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