So I've been struggling with an error which shows that the code is too long to process, so I decided to split a View struct into multiple some Views.
That hasn't worked well as it shows even more errors.
Here is some of the code:
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)
if gameover {
var body: some View {
ZStack { // 1
bg.ignoresSafeArea()
VStack {
gameoverscreen()
}
}
}
} else if (page == "main") {
var body: some View {
ZStack { // 1
bg.ignoresSafeArea()
VStack {
mainpage()
}
}
}
} else if (page == "multiplication game") {
var body: some View {
ZStack { // 1
bg.ignoresSafeArea()
VStack {
multiplicationgame()
}
}
}
} else if (page == "addition game") {
var body: some View {
ZStack { // 1
bg.ignoresSafeArea()
VStack {
additiongame()
}
}
}
}
On the first line, it shows the error: Type 'ContentView' does not conform to protocol 'View'.
On the if gameover { line, it shows the error: Expected declaration
Is there a way I can fix it, and if there is, how? Thanks