Hi, this is a follow-up to “Where do I put this conditional?” I’ve put in a function, setupB, to put in 81 buttons where the labels are made up from an 81 character string that summarizes either the original sudoku puzzle or the solution. My question is this: how do I get that code into a view as 81 buttons? Thank you.
func setupB() -> String {
var str = ""
for i in 0..<81 {
str += "Button {buttonWasTapped(currTag:" + String(i) + ")"
str += "} label: {Text((showSolution ? solution : original).dropFirst(" + String(i) + ") .dropLast(" + String(80-i) + "))"
str += ".foregroundColor(original.dropFirst(" + String(i) + ") .dropLast(" + String(80-i) + ") == \"0\" ? cDynamic : cStatic)"
str += "}.tag(" + String(i) + ") "
}
return str
}
var body: some View {
VStack {
Text("SUDOKU")
.padding(.bottom, 55)
Toggle("Show Solution", isOn: $showSolution)
.toggleStyle(SwitchToggleStyle(tint: cDynamic))
.padding(.leading, 42).padding(.trailing, 42)
Text(setupB())
}
}
Full project at GitHub - 56phil/Sudoku-SwiftUI