0

I have this Multiplatform app project I started with Xcode 12 beta 5, 3 days ago I updated Xcode to the latest version (12.0, build 12A7209) from App Store and now there's a problem with this piece of code

.navigationBarItems(trailing: HStack {
       Button(action: {
           self.showSettings.toggle()
        }, label: {
           Image(systemName: "gear").font(.system(size: 30))
        })
        .sheet(isPresented: $showSettings, content: {
           SettingsView(showSheet: $showSettings)
        })
  })

When I try to add a leading HStack:

.navigationBarItems(leading: HStack {
        Button("Hello") {
             print("Hello")
        }
    }, trailing: HStack {
       Button(action: {
           self.showSettings.toggle()
        }, label: {
           Image(systemName: "gear").font(.system(size: 30))
        })
        .sheet(isPresented: $showSettings, content: {
           SettingsView(showSheet: $showSettings)
        })
  })

I get this error: The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

Edit: I tried to replicate it in a new project but I don't get the error so this happen only on this "old" project

  • try to refactor your HStack to a small function. – JIE WANG Sep 22 '20 at 13:41
  • Can't reproduce. Your code compiles for me (when filled out). Please show [mcve] - complete example that should actually compile but gives this error instead. – matt Sep 22 '20 at 15:56

3 Answers3

0

As it was already mentioned, breaking your code into smaller portions should solve this issue. However, since updating to Xcode 12, whenever there's any error in the code, such as wrong variable names, this error seems to be thrown.

Looking at your code, I can't see any error. Make sure the SettingsView has no errors too.

kyrers
  • 489
  • 1
  • 6
  • 22
0

I solved replacing HStack in leading with a separated custom View I created. I don't know why he gave me that error, it works in other projects.

.navigationBarItems(leading: HStack{
      Button(action: {
          self.showSettings.toggle()
      }, label: {
          Image(systemName: "gear").font(.system(size: 25))
      })
      .sheet(isPresented: $showSettings, content: {
            SettingsView(showSheet: $showSettings)
      })
}, trailing: AddTaskButton().environmentObject(self.stateController))
-1

There are a bunch of articles out there on how to speed up compiling and type-checking but the ones that have helped me the most are adding the type to all the variables such as var showSheet: Bool and when I am having issues I add the type checking warning -Xfrontend -warn-long-expression-type-checking=<limit> to Build Settings>Swift Compiler>Custom Flags>Other Swift Flags I started with 400 and work my way down from there.https://www.avanderlee.com/optimization/analysing-build-performance-xcode-10/

lorem ipsum
  • 21,175
  • 5
  • 24
  • 48