Reputation: 36333
I just switched to Swift 1.2 and now it does no longer like
let v = optionalVal as SomeThing ?? default
Apple's release notes do not tell anything about it. Sure I can use if nil
but the ??
was handy.
Upvotes: 0
Views: 204
Reputation: 236538
You just have to put it inside a parentheses and forced cast now needs an exclamation mark as! or as?:
let v = ( optionalVal as? SomeThing ) ?? default
UPDATE:
Apple has just released today Xcode6.3 Beta 2 and seems that it is not needed anymore:
Swift Compiler
This expression now parses correctly, without need for parentheses:
dict[someKey] as? Int ?? 5
Upvotes: 2