title: Multiple selection of row swift
body: <p>I am using a tableView to display data of users, I want to enable multiple user selection and for now it malfunctions in such that when I deselect a selected user, the user details still remains in the array which I am storing it inside. how can I fix this. below is my code currently</p>
  
  <pre><code>struct ChatUser {
     var id: String
  var name: String
  }
  
  var selectedUser: [ChatUser] = []
  
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
          if self.selectedUser.contains(self.users[indexPath.row]) {
              let myIndex = self.selectedUser.index(of: self.users[indexPath.row])
              self.selectedUser.remove(at: myIndex!)
          } else {
              self.selectedUser.append(self.users[indexPath.row])
          }
  
          selectedUser.forEach { (user) in
              print("SELECTD \(user.id)")
          }
      }
  </code></pre>