Again, I have a vertical stack of horizontal stacks of buttons as follows.
And I want to send a few variables to EventView when the user clicks on a button.
If I just want to send two variables to it,
the compiler didn't complain. For the third variable, it says
Thank you
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
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?SwiftUI the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
Thank you