Too Complex To Check Code in Reasonable Time?

Again, I have a vertical stack of horizontal stacks of buttons as follows.

Code Block
import SwiftUI
struct ContentView: View {
@State private var eventPresented = Bool()
@State private var selectedEventIndex = Int()
@State private var monthSelection = Int()
var body: some View {
VStack {
VStack(spacing: 0.0) {
HStack(spacing: 0.0) {
ForEach((0...6), id: \.self) {
index in
Button(buttonTitles[index] ?? "") {
eventPresented = true
selectedEventIndex = index + 1 - self.weekIndex
}
.foregroundColor(titleColors[index])
.overlay(Text(eventNumbers[index] ?? "").font(.footnote).foregroundColor(.blue).offset(x: -16, y: -16))
.buttonStyle(BorderlessButtonStyle())
.frame(width: 48, height: 48, alignment: .center)
.background(RoundedRectangle(cornerRadius: 2)
.fill(fillColors[index])
.shadow(color: shadowColors[index], radius: 2, x: 0, y: 0)
)
.sheet(isPresented: $eventPresented) {
EventView(eventVisible: self.$eventPresented, dayFromParent: self.$selectedEventIndex, monthFromParent: self.$monthSelection)
}
}
}
...
...
HStack(alignment: .top, spacing: 0.0) {
ForEach((35...36), id: \.self) {
index in
Button(buttonTitles[index] ?? "") {
eventPresented = true
selectedEventIndex = index + 1 - self.weekIndex
}
.foregroundColor(titleColors[index])
.overlay(Text(eventNumbers[index] ?? "").font(.footnote).foregroundColor(.blue).offset(x: -16, y: -16))
.buttonStyle(BorderlessButtonStyle())
.frame(width: 48, height: 48, alignment: .center)
.background(RoundedRectangle(cornerRadius: 2)
.fill(fillColors[index])
.shadow(color: shadowColors[index], radius: 2, x: 0, y: 0)
)
.sheet(isPresented: $eventPresented) {
EventView(eventVisible: self.$eventPresented, dayFromParent: self.$selectedEventIndex, monthFromParent: self.$monthSelection)
}
}
}
.frame(width: 336.0, height: 48.0, alignment: .leading)
}
}
}
}


And I want to send a few variables to EventView when the user clicks on a button.

Code Block
struct EventView: View {
@Binding var eventVisible: Bool
@Binding var dayFromParent: Int
@Binding var monthFromParent: Int
var body: some View {
VStack {
Text("Window sheet.")
Button("OK") {
self.eventVisible = false
print("month from parent: \(monthFromParent)")
print("day from parent: \(dayFromParent)")
}
}
.frame(width: 240, height: 180)
}
}


If I just want to send two variables to it,

Code Block
EventView(eventVisible: self.$eventPresented, dayFromParent: self.$selectedEventIndex)


the compiler didn't complain. For the third variable, it says


SwiftUI the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

I know what it means. Some say it could resolve the issue by making the data types of variables clearer. Others say you could use a function to return a variable for a somewhat complex algebra equation. But what can I do in my case? Does anybody have any suggestions?

Thank you
Looks like there is quite a bit of repetitive code, I'd extract it to subviews / shared components and in general try keeping views more lightweight.

But what can I do in my case? 

Your code shown lacks many things: buttonTitles, titleColors, eventNumbers, fillColors, shadowColors and weekIndex.
That unable to type-check may occur when there is some primitive errors in such declarations.

I cannot reproduce the issue with your current code shown filling missing parts by guess.
Please enough code to reproduce the issue.

That unable to type-check may occur when there is some primitive errors in such declarations.

OOPer, thank you. With all due respect, the code will run without the third parameter.

The variables are set up as follows.

Code Block
weekIndex = 2
for _ in 0..<2 {
buttonTitles.append("")
fillColors.append(Color.clear)
shadowColors.append(Color.clear)
titleColors.append(Color.clear)
}
for i in 0..<38 - 2 {
if i < numberOfDays {
buttonTitles.append(String(i + 1))
if let day = myDay {
if i + 1 == day {
fillColors.append(Color.green)
titleColors.append(Color.white)
} else {
fillColors.append(Color.white)
titleColors.append(Color.black)
}
} else {
fillColors.append(Color.white)
titleColors.append(Color.black)
}
shadowColors.append(Color.black.opacity(0.4))
} else {
buttonTitles.append("")
fillColors.append(Color.clear)
shadowColors.append(Color.clear)
titleColors.append(Color.clear)
}
}


If I run code with just one horizontal stack

Code Block
var body: some View {
VStack(spacing: 0.0) {
HStack(spacing: 0.0) {
ForEach((0...6), id: \.self) {
index in
Button(buttonTitles[index] ?? "") {
eventPresented = true
selectedEventIndex = index + 1 - self.weekIndex
}
.foregroundColor(titleColors[index])
.overlay(Text(eventNumbers[index] ?? "").font(.footnote).foregroundColor(.blue).offset(x: -16, y: -16))
.buttonStyle(BorderlessButtonStyle())
.frame(width: 48, height: 48, alignment: .center)
.background(RoundedRectangle(cornerRadius: 2)
.fill(fillColors[index])
.shadow(color: shadowColors[index], radius: 2, x: 0, y: 0)
)
.sheet(isPresented: $eventPresented) {
EventView(eventVisible: self.$eventPresented, dayFromParent: self.$selectedEventIndex, monthFromParent: 11)
}
}
}
.frame(width: 336.0, height: 48.0, alignment: .leading)
}
}


, the compiler won't do it.

Looks like there is quite a bit of repetitive code, I'd extract it to subviews / shared components and in general try keeping views more lightweight. 

ilionic, thank you.

If I run code with just one horizontal stack like

Code Block
var body: some View {
VStack(spacing: 0.0) {
HStack(spacing: 0.0) {
ForEach((0...6), id: \.self) {
index in
Button(buttonTitles[index] ?? "") {
eventPresented = true
selectedEventIndex = index + 1 - self.weekIndex
}
.foregroundColor(titleColors[index])
.overlay(Text(eventNumbers[index] ?? "").font(.footnote).foregroundColor(.blue).offset(x: -16, y: -16))
.buttonStyle(BorderlessButtonStyle())
.frame(width: 48, height: 48, alignment: .center)
.background(RoundedRectangle(cornerRadius: 2)
.fill(fillColors[index])
.shadow(color: shadowColors[index], radius: 2, x: 0, y: 0)
)
.sheet(isPresented: $eventPresented) {
EventView(eventVisible: self.$eventPresented, dayFromParent: self.$selectedEventIndex, monthFromParent: 11)
}
}
}
.frame(width: 336.0, height: 48.0, alignment: .leading)
}
}


, the compiler won't do it. Could you suggest to me how I could improve it? Thank you.

The variables are set up as follows.

Please show enough code to reproduce the issue. That fragment of code does not help.

, the compiler won't do it.

What do you mean?
Oops, my apology... It was just a coding error that has caused this compiler error. I guess that's what OOPer said under a similar topic. Silly me...
Too Complex To Check Code in Reasonable Time?
 
 
Q