swift - 为什么我需要在这个 Swift 开关中使用默认情况?
问题描述
我相信以下 Swift 代码应该可以编译,但是编译器会出现Switch must be exhaustive
错误。是否有关于Int
减法的特殊属性允许“大于 0”、“小于 0”和“等于 0”之外的可能结果?
public enum MediaOrientation {
case portrait
case landscape
case square
init(width: Int, height: Int) {
switch width - height {
case let x where x == 0: self = .square
case let x where x < 0: self = .portrait
case let x where x > 0: self = .landscape
}
}
}
解决方案
推荐阅读
- flutter - 如何使用 Streambuilder 和 firebase QuerySnapshot 使用 GroupedListView
- javascript - 如何在 CSS 中自动将 div 大小调整为其中的图像大小?
- javascript - 使用 Mongoose 从 MongoDB 中的对象中删除元素
- javascript - 如何创建阿拉伯键盘的脚本?
- azure - Azure 函数 - local.settings.json 与 launchSettings.json
- serenity-platform - 我在 Endpoint 中收到 system.string 值错误?
- php - PHPMailer 接受原始文件名作为附件,但不作为变量
- r - 嵌套类实例 (OOP) 上的 R 方法
- swift - Firestore - 如何将多个字段查询到单个数组
- angular - 在 Angular 中手动重新渲染 FusionChart