简体   繁体   English

Swift 编译器无法在合理的时间内对该表达式进行类型检查; 尝试将表达式分解为不同的子表达式

[英]Swift The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

Following is method from a library in my project以下是我项目中库中的方法

 public convenience init(hueRotate: Double) {
    let c = cos(hueRotate)
    let s = sin(hueRotate)
    let m1 = [0.213, 0.715, 0.072,
              0.213, 0.715, 0.072,
              0.213, 0.715, 0.072]
    let m2 = [0.787, -0.715, -0.072,
              -0.213, 0.285, -0.072,
              -0.213, -0.715, 0.928]
    let m3 = [-0.213, -0.715, 0.928,
              0.143, 0.140, -0.283,
              -0.787, 0.715, 0.072]
    let a = { i in
        m1[i] + c * m2[i] + s * m3[i]
    }
    self.init(values: [a(0), a(1), a(2), 0, 0,
                       a(3), a(4), a(5), 0, 0,
                       a(6), a(7), a(8), 0, 0,
                       0, 0, 0, 1, 0])
}

on this following part of code I am getting compiler error saying The compiler is unable to type-check this expression in reasonable time;在以下代码部分中,我收到编译器错误提示编译器无法在合理的时间内对该表达式进行类型检查; try breaking up the expression into distinct sub-expressions尝试将表达式分解为不同的子表达式

let a = { i in
    m1[i] + c * m2[i] + s * m3[i]
}

How to fix this?如何解决这个问题?

Swift is having a problem with your equation being too long in the closure of var a . Swift 在 var a的闭包中遇到方程太长的问题。 Try splitting the expression into smaller ones, like this:尝试将表达式拆分为更小的表达式,如下所示:

let a = { i in
        c * m2[i]
    }
let b = { i in
        s * m3[i]
    }

let c = { i in
        m1[i]
    }

self.init(values: [a(0) + b(0) + c(0),
                   a(1) + b(1) + c(1),
                   a(2) + b(2) + c(2),
                   0, 0,
                   a(3) + b(3) + c(3),
                   a(4) + b(4) + c(4),
                   a(5) + b(5) + c(5),
                   0, 0,
                   a(6) + b(6) + c(6),
                   a(7) + b(7) + c(7),
                   a(8) + b(8) + c(8),
                   0, 0, 0, 0, 0, 1, 0])

It should be enough to tell the compiler what a returns so change the declaration to告诉编译器a返回什么就足够了,因此将声明更改为

let a = { (i) -> Double in
    m1[i] + c * m2[i] + s * m3[i]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 编译器无法在合理的时间内对这个表达式进行类型检查。 尝试将表达式分解为不同的子表达式 - The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions Swift-表情过于复杂,无法在合理的时间内解决; 考虑将表达式分解为不同的子表达式 - Swift - Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions 表达太复杂,无法在合理的时间内解决; 考虑将表达式分解为不同的子表达式? - expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions? 表达过于复杂,无法在合理的时间内解决。 考虑将表达式分解为不同的子表达式 - Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions 编译器无法在合理时间内对该表达式进行类型检查 --> Xcode swift - The compiler is unable to type-check this expression in reasonable time --> Xcode swift 声明数组时出现编译器错误:编译器无法进行类型检查……不同的子表达式 - Compiler error while declaring an array: compiler is unable to type-check … distinct sub-expressions 编译器无法在合理的时间内对该表达式进行类型检查 SWIFTUI? - The compiler is unable to type-check this expression in reasonable time SWIFTUI? 我的问题:编译器无法在合理的时间内对该表达式进行类型检查; - My problem: The compiler is unable to type-check this expression in reasonable time; 编译器无法在 SwiftUI 中的合理时间内对该表达式进行类型检查? - The compiler is unable to type-check this expression in a reasonable time in SwiftUI? SwiftUI:! [Array] 编译器无法在合理的时间内对该表达式进行类型检查 - SwiftUI:! [Array] the compiler is unable to type-check this expression in reasonable time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM