更新 xCode 后,我的代码中出现了这个错误:
The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
代码:
//check popup in window frame
let spaceFromLeftSide = cutOutViewX.constant + cutOutViewWidth.constant/2 - (options.textWidth + padding*2)/2
if spaceFromLeftSide < 0{
if options.side == .bottom {
messageRightSpaceFromBottomDot.constant -= spaceFromLeftSide - padding
}
else if options.side == .top{
messageRightSpaceFromTopDot.constant += spaceFromLeftSide - padding
}
}
let spaceFromRightSide = cutOutViewX.constant + cutOutViewWidth.constant/2 + (options.textWidth + padding*2)/2
if spaceFromRightSide > targetView.frame.size.width{
if options.side == .bottom {
messageRightSpaceFromBottomDot.constant -= spaceFromRightSide - ( targetView.frame.size.width )
}
else if options.side == .top{
messageRightSpaceFromTopDot.constant += spaceFromRightSide - ( targetView.frame.size.width )
}
}
行错误:
let spaceFromRightSide = cutOutViewX.constant + cutOutViewWidth.constant/2 + (options.textWidth + padding*2)/2
如何解决这个问题?
最佳答案
The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
当 swift 编译器发现表达式计算冗长时,会出现此错误。更多详情 check here
要解决这个问题,您只需将表达式分解成更小的部分。就像:
let cutOutxOrigin = 3 * cutOutViewX.constant / 2
let actualPadding = (options.textWidth + padding * 2) / 2
let spaceFromRightSide = cutOutxOrigin + actualPadding
关于ios - 编译器无法对这个表达式 swift 4 进行类型检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52382645/