What to use to update multiple views at once?

Hi! I am trying to make a maze game, and right now I am simply working on generating the maze. I have code that randomizes the contents of an array called "right". This array has enough members to fill what the maze size is, but when I run my code, the views don't update, the ForEach function seems to make it so it cannot read data from my DataBase. Please help me?

import SwiftUI

struct ContentView: View {
   
  @StateObject var data: DataBase
   
  @StateObject var trafficControl: TrafficControl
   
  var body: some View {

    ZStack{
      Group{
        LazyVStack{
           
          ForEach(1...data.size, id: \.self) { index in
            LazyHStack {
              ForEach(1...data.size, id: \.self) { box in
                Rectangle().fill(Color.gray).frame(width: 90, height: 90, alignment: .center).scaledToFill().padding(-4)
              }
          }
             
          }
        }
        LazyVStack{
          ForEach(1...(data.size), id: \.self) { index in
            LazyHStack {
              ForEach(1...(data.size + 1), id: \.self) { box in
                if data.**** == 1 {
                Rectangle().fill(Color.gray).frame(width: 6, height: 90, alignment: .center).scaledToFill().padding(.trailing, 38).padding(.leading, 38).padding(.top, -4).padding(.bottom, -4)
                }
                else {
                  Rectangle().fill(Color.black).frame(width: 6, height: 90, alignment: .center).scaledToFill().padding(.trailing, 38).padding(.leading, 38).padding(.top, -4).padding(.bottom, -4)
                }
              }
            }
          }
        }
      LazyHStack{
        ForEach(1...data.size, id: \.self) { index in
          LazyVStack {
            ForEach(1...(data.size + 1), id: \.self) { box in
              Rectangle().fill(
                Color.black).frame(width: 90, height: 6, alignment: .center).scaledToFill().padding(.top, 38).padding(.bottom, 38).padding(.trailing, -4).padding(.leading, -4)
            }
          }
        }
      }
        Rectangle().fill(Color.white).frame(width: 60, height: 60, alignment: .center).scaledToFill()
      }.offset(x: CGFloat(data.ex), y: CGFloat(data.why)).onAppear(){
        print("\(data.size/2 + 1)")
      }
       
      Circle().fill(Color.black).frame(width: 20, height: 20, alignment: .center).scaledToFill()
       
       
    }.gesture(DragGesture(minimumDistance: 40)
      .onEnded { endedGesture in
      if (endedGesture.location.x - endedGesture.startLocation.x) > 0 {
        if (endedGesture.location.y - endedGesture.startLocation.y) > (endedGesture.location.x - endedGesture.startLocation.x) {
          data.why -= 90
        }
        else if (endedGesture.startLocation.y - endedGesture.location.y) > (endedGesture.location.x - endedGesture.startLocation.x) {
          data.why += 90
        }
        else {
          data.ex -= 90
        }
      }
        else if (endedGesture.startLocation.x - endedGesture.location.x) > 0 {
          if (endedGesture.location.y - endedGesture.startLocation.y) > (endedGesture.startLocation.x - endedGesture.location.x) {
            data.why -= 90
          }
          else if (endedGesture.startLocation.y - endedGesture.location.y) > (endedGesture.startLocation.x - endedGesture.location.x) {
            data.why += 90
          }
          else {
            data.ex += 90
          }
        }
        else if (endedGesture.startLocation.y - endedGesture.location.y) > (endedGesture.location.y - endedGesture.startLocation.y) {
          data.why += 90
        }
        else {
          data.why -= 90
        }
        data.corx = data.ex/90
        data.cory = data.why/90
      }
     
  )}
     
  }

struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
    ContentView(data: DataBase(), trafficControl: TrafficControl())
  }
}

Please be more precise.

ForEach function seems to make it so it cannot read data from my DataBase

  • Which ForEach loop (not a function) ?
  • How is data populated ?
  • Are you sure data is not empty when you call in ForEach loops ?
What to use to update multiple views at once?
 
 
Q