简体   繁体   English

Xcode 编译器错误:编译器无法在合理的时间内对该表达式进行类型检查 (Xcode 12.0 SwiftUI)

[英]Xcode Compiler error: The compiler is unable to type-check this expression in reasonable time (Xcode 12.0 SwiftUI)

(Xcode 12.0, SwiftUI) This code was working for me for almost 6 months without any problem I just got this error yesterday without any editing. (Xcode 12.0,SwiftUI)这段代码为我工作了将近 6 个月,没有任何问题我昨天刚收到这个错误,没有进行任何编辑。 I tried a lot to clean the code and make it shorter but nothing worked for me.我尝试了很多来清理代码并使其更短,但没有任何效果对我有用。

GeometryReader { (geometry: GeometryProxy) in

  ForEach(0..<5) { index in

    Group {

      Circle()
        .foregroundColor(Color("GreyOne"))
        .frame(width: geometry.size.width / 5, height: geometry.size.height / 5)

        .scaleEffect(!self.isAnimating ? 1 - CGFloat(index) / 5 : 0.2 + CGFloat(index) / 5)

        .offset(y: geometry.size.width / 10 - geometry.size.height / 2)

      }.frame(width: geometry.size.width, height: geometry.size.height)

        .rotationEffect(!self.isAnimating ? .degrees(0) : .degrees(360))

        .animation(Animation
            
            .timingCurve(0.5, 0.15 + Double(index) / 5, 0.25, 1, duration: 1.5)

          .repeatForever(autoreverses: false))

    }

}.aspectRatio(1, contentMode: .fit)

    .onAppear {

      self.isAnimating = true

    }

You can move out parts of your View into separate private functions and just call those from body .您可以将View移出到单独的私有函数中,然后从body调用它们。 You had a couple of compiler errors in your code, such as not passing x to the offset function or not converting all Int s to CGFloat .您的代码中有几个编译器错误,例如未将x传递给offset函数或未将所有Int转换为CGFloat Once you break up the body of your View , the real errors will surface.一旦分解了Viewbody ,真正的错误就会浮出水面。

Here's the compiling version of your code, using 2 private functions to build parts of the body of your View .这是您的代码的编译版本,使用 2 个私有函数来构建View body的一部分。

struct YourView: View {
    @State private var isAnimating = false

    var body: some View {
        GeometryReader { geometry in
            ForEach(0..<5) { index in
                Group {
                    circle(geometry: geometry, index: index)
                }
                .frame(width: geometry.size.width, height: geometry.size.height)
                .rotationEffect(!self.isAnimating ? .degrees(0) : .degrees(360))
                .animation(animation(index: index))
            }
        }
        .aspectRatio(1, contentMode: .fit)
        .onAppear {
            self.isAnimating = true
        }
    }

    private func animation(index: Int) -> Animation {
        Animation
            .timingCurve(0.5, 0.15 + Double(index) / 5, 0.25, 1, duration: 1.5)
            .repeatForever(autoreverses: false)
    }

    private func circle(geometry: GeometryProxy, index: Int) -> some View {
        let width = geometry.size.width
        let height = geometry.size.height
        let yOffset = width / 10 - height / 2
        let nonAnimatingScale = 1 - CGFloat(index) / CGFloat(5)
        let animatingScale = 0.2 + CGFloat(index) / CGFloat(5)
        return Circle()
            .foregroundColor(Color("GreyOne"))
            .frame(width: width / 5, height: height / 5)
            .scaleEffect(self.isAnimating ? animatingScale : nonAnimatingScale)
            .offset(x: 0, y: yOffset)
    }
}

暂无
暂无

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

相关问题 编译器无法在合理时间内对该表达式进行类型检查 --&gt; Xcode swift - The compiler is unable to type-check this expression in reasonable time --> Xcode swift 编译器无法在合理的时间内对该表达式进行类型检查 SWIFTUI? - The compiler is unable to type-check this expression in reasonable time SWIFTUI? 编译器无法在 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 我的问题:编译器无法在合理的时间内对该表达式进行类型检查; - My problem: The compiler is unable to type-check this expression in reasonable time; 编译器无法在合理的时间内对这个表达式进行类型检查。 尝试将表达式分解为不同的子表达式 - The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions Swift 编译器无法在合理的时间内对该表达式进行类型检查; 尝试将表达式分解为不同的子表达式 - Swift The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions 编译器无法对该表达式 swift 4 进行类型检查? - The compiler is unable to type-check this expression swift 4? 编译器无法对 Swift 5 表达式进行类型检查? - The compiler is unable to type-check expression Swift 5? 如何解决 SwiftUI 中的“编译器无法进行类型检查……”错误? - How can I solve “The compiler is unable to type-check …” error in SwiftUI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM