The idiom for dealing with optionals in Swift seems excessively verbose, if all you want to do is provide a default value in the case where it\'s nil:
if let
if you wrote:
let result = optionalValue ?? 50
and optionalValue != nil then result will be optional too and you will need unwrap it in future
But you can write operator
infix operator ??? { associativity left precedence 140 }
func ???(optLeft:T?, right:T!) -> T!
{
if let left = optLeft
{
return left
}
else { return right}
}
Now you can:
let result = optionalValue ??? 50
And when optionalValue != nil then result will be unwraped