title: Check box with the data taken from the database - Swift - SwiftUi - Firebase
body: <p>I am creating a section within my app where it will be possible to see the list of users and their permissions (inserted in the form of an array) inserted into the database.</p>
  <p>I view the user's information and permissions in this way:</p>
  <pre><code>        List(administratorManager.users) { user in
  
              HStack {
                  VStack(alignment: .leading) {
                      
                      Text(user.number).font(.subheadline) 
                      Text(user.name).font(.subheadline) 
                      Text(user.surname).font(.subheadline) 
                      
                      VStack(alignment: .leading){
                          Text(&quot;Permessi&quot;)
                              .font(.title2)
                              .fontWeight(.bold)
                              .padding(1)
                          
                          HStack{
                              Image(systemName: user.permessi[0] ? &quot;checkmark.square.fill&quot; : &quot;square&quot;)
                                  .foregroundColor(user.permessi[0] ? Color(UIColor.systemBlue) : Color.secondary)
                                          .onTapGesture {
                                              user.permessi[0].toggle()
                                          }
                              Text(&quot;0&quot;)
                                  .onTapGesture {
                                      user.permessi[0].toggle()
                                  }
                          }
                          
                          HStack{
                              Image(systemName: user.permessi[1] ? &quot;checkmark.square.fill&quot; : &quot;square&quot;)
                                  .foregroundColor(user.permessi[1] ? Color(UIColor.systemBlue) : Color.secondary)
                                          .onTapGesture {
                                              user.permessi[1].toggle()
                                          }
                              Text(&quot;1&quot;)
                                  .onTapGesture {
                                      user.permessi[0].toggle()
                                  }
                          }
                      }
                  }
          }
      }
      .onAppear() {
          self.administratorManager.fetchData(collection: &quot;Admins&quot;) 
      }
  </code></pre>
  <p>The data is constantly read from the database in this way and saved in a structure:</p>
  <pre><code>func fetchData(collection: String) { 
      DatabaseFirestore.collection(collection).addSnapshotListener { (querySnapshot, error) in 
          guard let documents = querySnapshot?.documents else {
              print(&quot;No documents&quot;) 
              return
          }
          
          self.users = documents.map { (queryDocumentSnapshot) -&gt; User in
              let data = queryDocumentSnapshot.data()
              let name = data[&quot;Nome&quot;] as? String ?? &quot;&quot; 
              let surname = data[&quot;Cognome&quot;] as? String ?? &quot;&quot; 
              let school = data[&quot;Scuola&quot;] as? String ?? &quot;&quot; 
              let orari = data[&quot;Orari&quot;] as? [String] ?? [] 
              let permessi = data[&quot;Permessi&quot;] as? [Bool] ?? [] 
              let number = queryDocumentSnapshot.documentID 
  
              return User(name: name, surname: surname, school: school, orari: orari, permessi: permessi, number: number) 
          }
      }
  }
  </code></pre>
  <p>This is the structure:</p>
  <pre><code>struct User: Identifiable {
      var id: String = UUID().uuidString
      var name: String
      var surname: String
      var school: String
      var orari: [String]
      var permessi: [Bool]
      var number: String
  }
  </code></pre>
  <p>The data is correctly displayed like this:</p>
  <p><a href="https://i.stack.imgur.com/z7YCZ.png" rel="nofollow noreferrer">Phone of the screen</a></p>
  <p><a href="https://i.stack.imgur.com/AWc9Q.png" rel="nofollow noreferrer">Photo of the database</a></p>
  <p>The problem arises when the checkbox is pressed. when this is added I am told that user is a let constant:</p>
  <pre><code>.onTapGesture {
      user.permessi[0].toggle()
  }
  </code></pre>
  <p>How could I change the code to make it work?</p>
  <p>Also I tried to shorten the code through a forEach:</p>
  <pre><code>ForEach(user.permessi) p in  {
      HStack{
          Image(systemName: p ? &quot;checkmark.square.fill&quot; : &quot;square&quot;)
              .foregroundColor(p ? Color(UIColor.systemBlue) : Color.secondary)
              .onTapGesture {
                                                  
              }
              Text(&quot;0&quot;)
                  .onTapGesture {
                                          
              }
              .padding(1)
       }
  }
  </code></pre>
  <p>I know it is wrong but no error message is displayed. How do I resolve?</p>