operators - swift 1.2 ??运算符(operator)

标签 operators swift

我刚刚切换到 Swift 1.2,现在它不再喜欢了

let v = optionalVal as SomeThing ?? default

Apple 的发行说明没有说明任何相关内容。当然我可以使用 if nil?? 很方便。

最佳答案

您只需将它放在括号内,强制转换现在需要一个感叹号!或者作为?:

let v = ( optionalVal as? SomeThing ) ?? default

更新:

Apple 今天刚刚发布了 Xcode6.3 Beta 2,似乎不再需要它了:

Swift Compiler

This expression now parses correctly, without need for parentheses:

dict[someKey] as? Int ?? 5

关于operators - swift 1.2 ??运算符(operator),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28618671/

相关文章:

c++ - 是否可以在 C++ 中声明 operator= private 并同时由编译器合成

c++ - 我不明白 std::shared_ptr 的 -> 运算符

c++ - 与运算符(operator)混淆

c++ - 需要左值作为增量操作数错误

ios - 在 iOS 应用程序测试期间,如何访问主机应用程序中的单例实例?

vba - VBA 中不存在 += 运算符吗?

ios - Swift OpenGL 未解析标识符 kCGImageAlphaPremultipliedLast

ios - CocoaPods - 无法找到规范

ios - 将 CVPixelBuffer 转换为 Mat (OpenCV)

ios - 如何自动调整包含多行 UIButton 的 UITableViewCell 的高度?