添加 4 个滑块值时表达式太复杂,无法在合理的时间错误中解决

Expression was too complex to be solved in reasonable time error while adding 4 slider values

我尝试添加这 4 个滑块值,但收到此错误,我该如何解决?代码:

@IBAction func mathValueChanged(_ sender: UISlider) {
    let total = MathCriASlider.value + MathCriBSlider.value + MathCriCValue.value + MathCriDSlider.value
    mathValue.text = "/(total)"
}

确实令人沮丧,我很惊讶在 Swift 的更新版本中看到这一点。在过去,我只需要分解表达式。例如

let A = MathCriASlider.value
let B = MathCriBSlider.value
let C = MathCriCSlider.value
let D = MathCriDSlider.value
let total = A + B + C + D

如果它仍然报错,您甚至可能需要计算一对小计。

第二行需要修复,你的字符串插值是错误的。使用

mathValue.text = "\(total)"  // I changed the slash to a backslash