How do I use ?: in Swift?

Viewed 5283

I love this syntax in Objective-C, where a question mark and colon let you use a backup value:

NSString const name = [self getName] ?: @"backup";

and I want to use the same in Swift, but I get this when I try:

<code>let name = getName() ?: "backup";</code> results in errors where the compiler completely doesn't recognize the syntax

Is there any way to do this in Swift? If not, can I write a custom infix operator to do it?

1 Answers
Related