且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

二元运算符/不能应用于 Int 和 Double 类型的操作数

更新时间:2022-03-12 22:30:48

高度和宽度都将被推断为 Int 类型.因此 area 也是 Int 类型,而 10.762 是 Double 类型.

height and width will both be inferred as of type Int. Therefore area is also of type Int whilst 10.762 is a Double.

在 Swift 中安全是最重要的,所以你需要有两个相同类型的操作数.

And in Swift safety is paramount so you'll need to have both operands of same type.

解决方案是(如 Eric D. 建议的)将区域转换为双精度:

Solution is (as Eric D. suggested) is to convert area to a Double:

let areaInMeters = Double(area) / 10.762