title: Trying to create a grid of numbers that must be clicked in order and when clicked the background changes color SWIFTUI
body: <p>As the title says I am trying to create a grid of random numbers that must be clicked in ascending order and when pressed the background changes color so they're no longer visible.</p>
  <p>I figured out how to create the grid from 0 to what ever size grid I want (5x5, 10x10, etc...)</p>
  <p>I want the background to be white to start and then when the button is pressed it changes to black</p>
  <p>The two biggest issues I'm having are all of the buttons turning black after I press on one button and the numbers randomize every time I press a button.</p>
  <p>Any one have any ideas?</p>
  <pre><code>import SwiftUI
  
  struct ContentView: View {
  @State var buttonbackg = Color.white
  @State var gridsize = 100
  var body: some View {
      
      //make grid
      let cellCount = (gridsize/10)
      let r = numbrand(min: 00, max: ((gridsize/10) * (gridsize/10) - 1))
     
      ZStack{
          Rectangle()
              .ignoresSafeArea()
              .background(Color.black)
          VStack{
              Text(&quot;Concentration Grid&quot;)
                  .font(.title)
              .foregroundColor(Color.white)
              .multilineTextAlignment(.center)
              .padding(.bottom)
              
              Spacer()
          }
          VStack(spacing:3) {
              
              
              Spacer()
            
                 ForEach(1...cellCount, id:\.self) { i in
                 
                 HStack(spacing:3) {
                     Spacer()
                     ForEach(1...cellCount, id:\.self) { c in
                         
                         let a = r()
                         
                         ZStack {
                            
                            
                             
                             Button(action:{
                                 if (self.buttonbackg == .white) {
                                    self.buttonbackg = .black
                                  }
                             }){
                             
                             
                                 Text(&quot;\(a)&quot;)
                                 
                                 .foregroundColor(Color.black)
                                 .frame(width: 28, height: 28)
                                 .background(buttonbackg)
                                 .cornerRadius(5)
                                 .multilineTextAlignment(.center)
                                 .scaledToFit()
                                 .padding(.all, -2)
                                 Spacer()
                                     
                                 }
                             Spacer()
                         }
                         
                         
                        }
                     
                    }
                     Spacer()
               }
              Spacer()
            }
      }
        }
      //^grid
  
  
  
  func numbrand(min: Int, max:Int) -&gt; () -&gt; Int{
      //let array: [Int] = Array(min...max)
      var numbers: [Int] = []
      return {
          if numbers.isEmpty {
              numbers = Array(min...max)
          }
          
          let index = Int(arc4random_uniform(UInt32(numbers.count)))
          return numbers.remove(at: index)
      }
      
  }
  }
  
  struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
      ContentView()
  }
  }
  </code></pre>