Skip to content

Instantly share code, notes, and snippets.

@adamnemecek
Created June 29, 2016 15:59
Show Gist options
  • Save adamnemecek/7e3802df3d8f890fc8f8a83469c22d4f to your computer and use it in GitHub Desktop.
Save adamnemecek/7e3802df3d8f890fc8f8a83469c22d4f to your computer and use it in GitHub Desktop.
Swift coalescing assignment operator
infix operator ??= {
associativity right
precedence 90
assignment
}
func ??=<T>(inout optional: T?, @autoclosure defaultValue: () -> T?) {
optional = optional ?? defaultValue()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment