swift - 表达式对于编译器来说太复杂了——如何将这个表达式分解成不同的子表达式?

标签 swift

错误与乘数变量有关。为什么它对编译器来说太复杂了?我将如何重写它?我应该发布整个 drawRect 函数吗?

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

// Progress is a value between 1.0 and -0.5, determined by the current wave idx, which is used to alter the wave's amplitude.
        var progress = CGFloat(1.0 - Float(i) / Float(numberOfWaves))
        var normedAmplitude = (1.5 * progress - 0.5) * amplitude

        var multiplier = CGFloat(min(1.0, (progress / 3.0 * 2.0) + (1.0 / 3.0))) // error point
        waveColor.colorWithAlphaComponent(multiplier * CGColorGetAlpha(waveColor.CGColor)).set()

最佳答案

单独计算progress/3.0 * 2.0即可。

let calc = progress / 3.0 * 2.0
var multiplier = CGFloat(min(1.0, (calc) + (1.0 / 3.0)))

当在一行中计算太多时,可能会发生此错误。

关于swift - 表达式对于编译器来说太复杂了——如何将这个表达式分解成不同的子表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34886176/

相关文章:

ios - 快速计算 map 的距离和预计到达时间

SwiftUI 在 View 之间共享模型数据

iOS 使用嵌套请求加载表数据

ios - 如何减小自定义 iOS 框架的大小?

unit-testing - 如何在 Swift 中设置单元测试?

iPhone X 模拟器上的 iOS slider 滞后

swift - 火力地堡 + swift : Grab only the latest change for a child node

ios - AVPlayer 在缓冲时显示和隐藏加载指示器

swift - 如何等待 Action 结束来执行 SpriteKit 中的函数?

ios - 确保 View 的 IBOutlets 已被实例化