gpt4 book ai didi

Swift 3 - 表达式太复杂,无法在合理的时间内解决;考虑将表达式分解为不同的子表达式

转载 作者:搜寻专家 更新时间:2023-10-31 22:05:07 24 4
gpt4 key购买 nike

我遇到了这个错误,我不知道如何解决!我正在搜索所有解决方案,但无法解决!

Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions

编辑:

    func createTarget(id: Int) {

listdata = dbHelpr.getDatabase(rowId: id)

for data in listdata {

let lengthOfChar : CGFloat = data.ans.length
let yAxis : CGFloat = self.view.frame.height / 2 + 70

var width: CGFloat = view.frame.size.width - 40 // frame width
var targetWidth: CGFloat = (width - (lengthOfChar - 1) * 5) / lengthOfChar
var totalWidth: CGFloat = (targetWidth * lengthOfChar) + ((lengthOfChar - 1) * 5)

if targetWidth > 50 {
targetWidth = 50
}

for tar in data.ans.characters {


var xAxis : CGFloat = (width / 2) - (totalWidth / 2) + (tar * targetWidth) + (tar * 5) + 20

let targetLabel = UILabel(frame: CGRect(x: xAxis, y: yAxis, width: targetWidth, height: 5.0))
targetLabel.backgroundColor = .white
targetLabel.layer.masksToBounds = true
targetLabel.layer.cornerRadius = 5
targetLabel.text = String(describing: tar)
targetLabel.textAlignment = .center
targetLabel.textColor = .white
self.view.addSubview(targetLabel)

}

}

}

最佳答案

Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions

如前所述,打破它:

let preAxis1: GCFloat = (width / 2) - (totalWidth / 2) 
let preAxis2: GCFloat = (tar * targetWidth) + (tar * 5) + 20
let xAxis : CGFloat = preAxis1 + preAxis2

现在,这揭示了另一个(真正的)问题,而您所做的事情没有意义:

Binary operator '*' cannot be applied to operands of type 'Character' and 'CGFloat'

所以 tar 是一个 Character,而不是一个“数字”。在xAxis的计算中使用它是没有意义的。其实你要的是它的索引。

代替 for tar in data.ans.characters {,您可以这样做:

for (indexTar, tar) in data.ans.characters.enumerated() {

您正在迭代 data.ans 中的所有字符indexTar 是当前索引,tar字符。因此,在之前的 xAxis 计算中,将 tar 替换为 indexTar 会更有意义并且应该有效。

关于Swift 3 - 表达式太复杂,无法在合理的时间内解决;考虑将表达式分解为不同的子表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45219478/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com