This is my code (note that this isn't the whole code):
struct GrowingButton: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.padding()
.background(Color.blue)
.foregroundColor(.white)
.clipShape(Capsule())
.scaleEffect(configuration.isPressed ? 1.2 : 1)
.animation(.easeOut(duration: 0.2), value: configuration.isPressed)
}
}
struct multiplicationcheck: View {
var body: some View {
if (startgame == true) {
let confirmation = checkanswer(guess: username, aanswer: answer1 as! Int)
moreText = confirmation
}
if (page == "multiplication stage1"){
didfunc = genquesmulti()
answer1 = didfunc[0]
mainquestion = didfunc[1] as! String
} else if (page == "multiplication stage2"){
didfunc = genquesmulti2()
answer1 = didfunc[0]
mainquestion = didfunc[1] as! String
} else if (page == "multiplication stage3"){
didfunc = genquesmulti3()
answer1 = didfunc[0]
mainquestion = didfunc[1] as! String
} else if (page == "multiplication stage4"){
didfunc = genquesmulti4()
answer1 = didfunc[0]
mainquestion = didfunc[1] as! String
}
username = ""
startgame = true
}
}
struct additioncheck: View {
var body: some View {
if (startgame == true) {
let confirmation = checkanswer(guess: username, aanswer: answer1 as! Int)
moreText = confirmation
}
if (page == "addition stage1"){
didfunc = genquesadd()
answer1 = didfunc[0]
mainquestion = didfunc[1] as! String
} else if (page == "addition stage2"){
didfunc = genquesadd2()
answer1 = didfunc[0]
mainquestion = didfunc[1] as! String
} else if (page == "addition stage3"){
didfunc = genquesadd3()
answer1 = didfunc[0]
mainquestion = didfunc[1] as! String
} else if (page == "addition stage4"){
didfunc = genquesadd4()
answer1 = didfunc[0]
mainquestion = didfunc[1] as! String
} else if (page == "addition stage5"){
didfunc = genquesadd5()
answer1 = didfunc[0]
mainquestion = didfunc[1] as! String
} else if (page == "addition stage6"){
didfunc = genquesadd6()
answer1 = didfunc[0]
mainquestion = didfunc[1] as! String
} else if (page == "addition stage7"){
didfunc = genquesadd7()
answer1 = didfunc[0]
mainquestion = didfunc[1] as! String
}
username = ""
startgame = true
}
}
struct divisioncheck: View {
var body: some View {
if (startgame == true) {
let confirmation = checkanswer(guess: username, aanswer: answer1 as! Int)
moreText = confirmation
}
didfunc = genquesdivi()
answer1 = didfunc[0]
mainquestion = didfunc[1] as! String
username = ""
startgame = true
}
}
struct textquestion: View {
var body: some View {
Text(moreText).font(.body)
.padding(1).foregroundColor(.black).font(Font.system(.body, design: .rounded))
Text(mainquestion).padding().foregroundColor(.black).font(Font.system(.largeTitle, design: .rounded))
}
}
func reset(){
moreText = ""
timeRemaining = 60
score = 0
overall = 0
gameover = false
answer1 = 0
mainquestion = "Press submit to start"
startgame = false
}
struct ContentView: View {
var timer2 = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
let bg = LinearGradient(
gradient: Gradient(colors: [Color.pink, Color.yellow]),
startPoint: .top, endPoint: .bottom)
var body: some View {
ZStack { // 1
bg.ignoresSafeArea()
VStack {
if gameover {
gameoverscreen()
// some more code
} else if (page == "multiplication stage1" || page == "multiplication stage2" || page == "multiplication stage3" || page == "multiplication stage4") {
let stage = page.replacingOccurrences(of: "multiplication stage", with: "")
Text("Multiplication - Stage \(stage)").foregroundColor(.black).font(Font.system(.title, design: .rounded))
TextField(
"Answer",
text: username
).keyboardType(.numberPad).padding(10)
.font(Font.system(size: 15, weight: .medium, design: .rounded))
.overlay(RoundedRectangle(cornerRadius: 10).stroke(Color.blue, lineWidth: 1)).foregroundColor(.black)
.onSubmit {
multiplicationcheck()
}
Button("Submit") {
multiplicationcheck()
}
.buttonStyle(GrowingButton())
} else if (additionvalues.contains(page)) {
TextField(
"Answer",
text: username
).keyboardType(.numberPad).padding(10)
.font(Font.system(size: 15, weight: .medium, design: .rounded))
.overlay(RoundedRectangle(cornerRadius: 10).stroke(Color.blue, lineWidth: 1)).foregroundColor(.black)
.onSubmit {
additioncheck()
}
Button("Submit") {
additioncheck()
}
.buttonStyle(GrowingButton())
} else if (page == "division stage1"){
TextField(
"Answer",
text: username
).keyboardType(.numberPad).padding(10)
.font(Font.system(size: 15, weight: .medium, design: .rounded))
.overlay(RoundedRectangle(cornerRadius: 10).stroke(Color.blue, lineWidth: 1)).foregroundColor(.black)
.onSubmit {
divisioncheck()
}
Button("Submit") {
divisioncheck()
}
.buttonStyle(GrowingButton())
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
ContentView()
}
}
}
In the lines var body: some View {, in the ContentView struct, multiplicationcheck struct and additioncheck struct, I'm getting the error The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions. I understand why this is happening, but not how to fix it.
In the line var body: some View { in the divisioncheck struct, I am getting the error Type '()' cannot conform to 'View'. I don't understand why this error is happening.
If you could help me fix this, that would be great.
Thanks!
2
0
2.8k