Xcode 12中的类型检查错误:“编译器无法在合理的时间内对此表达式进行类型检查”

时间:2020-09-21 10:26:55

标签: xcode swiftui

几天前,我已将Xcode更新到版本12。当我打开一个现有项目时,新的Xcode出现错误:

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

该项目在以前的版本中运行正常。

这是我得到错误的代码:

    import SwiftUI

struct FaqView: View {
    @ObservedObject var viewModel = FaqViewModel()
    @State var sectionState: [String: Bool] = [:]
    
    init(){
        UITableView.appearance().backgroundColor = .init(red: 255, green: 255, blue: 255, alpha: 0.0)
        UITableViewCell.appearance().backgroundColor = .init(red: 255, green: 255, blue: 255, alpha: 0.0)
    }
    var body: some View {
        GeometryReader { geometry in
             return VStack(spacing: 0) {
                    VStack {
                        CustomHeader(titleText: "FAQ LIST") {
                            DashboardView()
                        }
                    }
                    .frame(width: geometry.size.width)
                    .padding(.top, 10)
                    .background(Color("B1"))
                    ZStack {
                        Image("App Background")
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .offset(y: -geometry.size.height/2.8)
                            .padding(.top, 100)
                        VStack {
                            List {
                                if self.viewModel.faqModel?.payload?.count ?? 0 > 0 {
                                    ForEach(self.viewModel.faqModel?.payload?[0] ?? []) { payload in
                                        Text("\(payload.title ?? "")".uppercased())
                                            .foregroundColor(Color("T7"))
                                            .padding(.leading, 22)
                                        ForEach(payload.child ?? []) { section in
                                            Section(
                                                header: HStack {
                                                    Image(self.sectionState[section.title ?? ""] ?? false ? "FAQ Minus Icon" : "FAQ Plus Icon")
                                                        .resizable()
                                                        .frame(width: self.sectionState[section.title ?? ""] ?? false ? 16 : 15, height: self.sectionState[section.title ?? ""] ?? false ? 3 : 15)
                                                    Text(section.title ?? "")
                                                        .foregroundColor(self.sectionState[section.title ?? ""] ?? false ? Color("T2") : Color("T8"))
                                                        .font(.system(size: 16))
                                                        .padding(.top, -2)
                                                }
                                                .onTapGesture {
                                                    withAnimation {
                                                        self.sectionState[section.title ?? ""] = !self.isExpanded(section.title ?? "")
                                                    }
                                                }
                                            ) {
                                                if self.isExpanded(section.title ?? "") {
                                                    VStack {
                                                        Text("\(section.childDescription ?? "")")
                                                            .padding(.leading, 22)
                                                            .foregroundColor(Color("T8"))
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            .listStyle(GroupedListStyle())
                        }
                        if self.viewModel.isFAQListAppeared {
                            LoaderView()
                                .offset(y: -70.0)
                        }
                    }
                    Spacer()
                }
                .edgesIgnoringSafeArea(.all)
                .onAppear {
                    self.viewModel.isFAQListAppeared = true
                    self.viewModel.fetchWithAF()
                }
            }
            
        }
        func isExpanded(_ section: String) -> Bool {
            sectionState[section] ?? false
        }
}

struct FaqView_Previews: PreviewProvider {
    static var previews: some View {
        FaqView()
    }
}

如果有人遇到此错误,请提供帮助。预先感谢。

1 个答案:

答案 0 :(得分:0)

我不确定,但是我认为在ForEach中展开可选数组的方式是错误的。不幸的是,我无法验证它,因为我不知道FaqViewModel,但是如果我注释除ForEach行之外的其他所有内容,则会收到错误“无法将类型'[Any]'的值转换为预期参数类型'范围'”