ios - 编译器无法对这个表达式 swift 4 进行类型检查?

标签 ios swift

更新 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/

相关文章:

ios - 在 iOS 中匹配按钮框架

ios - ViewController 偶尔会错过响应链?

ios - 如何将日期字符串快速转换为 NSDate 类型

iOS NSDateFormatter 忽略时区

ios - 注释未与核心数据一起出现

ios - 快速从单独的 View Controller 调用函数

ios - UNNotificationServiceExtension - 在应用程序处于事件状态时隐藏

ios - 图像在约束条件下未按预期工作

ios - swift 类中的 AWS 配置行导致线程 1 : EXC_BAD_INSTRUCTION

ios - 项目在 Xcode 9.0.1 上运行正常,但在 Xcode 9.2 上显示错误