A common feature in many languages, the Null Coalescing Operator, is a binary operator often used to shorten expressions of the type:
x = possiblyNullValue N
(Also see blog post)
No, Swift doesn't currently support a null coalescing operator.
A custom operator can be defined for Swift, with the following considerations regarding the Swift language:
Swift supports a null concept through its Optional type (a Discriminated Union of sorts) which either holds a value of the underlying type or no value (indicated by nil) and must be explicitly defined as being optional:
var a : String?
A non-optional type can never be nil, or assigned nil. Therefore a custom infix binary NCO can be expected to take an optional as its first parameter.
In Swift, custom operators can be comprised of the following characters only:
/ = - + * % < > ! & | ^ . ~
Given the choice of available characters, ||| (three pipes, no spacing) isn't terrible (similar to the double pipe OR in Javascript which is used like a NCO):
var a = String?
var z = a ||| "it's nil!"
println(z) //Output: it's nil!
operator infix ||| {}
@infix func ||| (left: T?, right: T) -> T {
if let l = left { return l }
return right
}