Post

Replies

Boosts

Views

Activity

Reply to The compiler is unable to type-check this expression in reasonable time in Xcode 12 with SwiftUI
This still seems to be an issue. Using Xcode 14.2 (14C18) on Ventura 13.2.1 (22D68) on an arm64 Macbook, I run into the same issues with some fairly simple stuff. The code below builds very fast. If I just make changes in this particular file and rebuild with the rest of the project cached, it takes about a second from build to launch. However, just adding one statement and the compiler would end up with The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions after using almost all available CPU power for about a minute. Here comes the code: struct ModelGroupDetailsView: View { @Binding var modelGroup: modelGroup private static let bottomPadding: CGFloat = 10 private static let insetNormal: CGFloat = 15 private static let insetDeep: CGFloat = 18 var body: some View { List { ForEach($modelGroup.objects) { $object in Section { VStack(alignment: .leading, spacing: 0) { if object.childObjects.count == 0 { Text("This object does not contain any childObjects.") .padding(.leading, Self.insetNormal) .padding(.bottom, Self.bottomPadding) } ForEach(object.childObjects) { childObject in Label(childObject.url.lastPathComponent, systemImage: "externaldrive") .foregroundColor(Color.black.opacity(0.6)) .padding(.leading, Self.insetNormal) .padding(.bottom, Self.bottomPadding / 2) .padding(.top, Self.bottomPadding / 2) let grandChildObjects = childObject.grandChildObjects if grandChildObjects.count == 0 { Text("This childObject does not contain any grandChildObjects.") .padding(.leading, Self.insetDeep) .padding(.bottom, Self.bottomPadding) .font(Font.system(size: 11)) } else { Table(of: GrandChildObject.self) { TableColumn("ID") { Text($0.id.description) } TableColumn("Tag") { Text($0.tag) } TableColumn("Creation date") { Text($0.creationDate.formatted()) } } rows: { ForEach(grandChildObjects) { TableRow($0) } } .frame(height: CGFloat(grandChildObjects.count) * 28 + 26) .padding(.bottom, Self.bottomPadding) .scrollDisabled(true) } if object.childObjects.last != childObject { if object.childObjects.last?.grandChildObjects.count ?? 0 > 0 { Divider() .padding(.bottom, Self.bottomPadding + 4) } else { Divider() .padding(.leading, Self.insetDeep) .padding(.bottom, Self.bottomPadding + 4) } } } if modelGroup.objects.last != object { Divider() .padding(.leading, Self.insetNormal) .padding(.bottom, Self.bottomPadding) } } } header: { HStack { Button(action: removeObject(object)) { Label("Remove object", systemImage: "trash") .labelStyle(.iconOnly) } .padding(6) .buttonStyle(RemoveButtonStyle()) Text(object.url.lastPathComponent) .font(Font.system(size: 13, weight: Font.Weight.medium)) .foregroundColor(Color.black) .frame(maxWidth: .infinity, alignment: .leading) } } } } .id(self.modelGroup) .toolbar { ToolbarItemGroup(placement: .principal) { Button(action: addObject) { Label("Create new object", systemImage: "plus") } .help("Add more objects") Spacer(minLength: 10) Button(action: popSnapshot) { Label("Remove latest grandchild", systemImage: "rectangle.stack.badge.minus") } .help("Remove the latest grandchild for all childObjects in modelGroup") Button(action: pushSnapshot) { Label("Create new grandchild", systemImage: "rectangle.stack.badge.plus") } .help("Create a new grandchild for all childObjects in modelGroup") } } .navigationTitle(modelGroup.name) } ... }
Mar ’23