- 此问题在此处已有答案**:
The compiler is unable to type-check this expression swift 4?(15个答案)
昨天关门了。
以下函数触发错误:* "编译器无法在合理的时间内对此表达式进行类型检查;尝试将表达式分解为不同的子表达式"*
func calculateCalSpent(age: Int, height: Int, currentWeight: Int, activityLevel: Int ) -> Int{
var cal = Int(66.47 + (13.75 * currentWeight) + (5.003 * height) - (6.755 * age))
print(cal)
return cal
// Men kg cm
}
当我用1代替cal作为回报时,一切都没问题,我该怎么办呢?
1条答案
按热度按时间zvms9eto1#
你混合了整数和浮点值。在这种特殊情况下,这似乎给类型检查器带来了问题。
由于这里需要浮点计算,请将所有
Int
显式转换为Double
以修复/解决此问题: