title: How to add selected indexes of tableview sections to an array
body: <p>I have a <code>tableView</code> with <code>section headers</code> and I want to append a certain user input to multiple selected <code>headers</code>. I have created the <code>section headers</code> and am able to change the image on the <code>section header</code> to show that it is selected but I want to create an <code>array</code> of those selected. </p>
  
  <p>Here is my code for the <code>section header</code>:</p>
  
  <pre><code>func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -&gt; UIView? {
      let userModel = Data.userModels[section]
      let cell = tableView.dequeueReusableCell(withIdentifier: "nameCell") as! NameHeaderTableViewCell
  
      cell.setup(model: userModel)
      cell.checkMarkButton.addTarget(self, action: #selector(handleTap), for: .touchUpInside)
      cell.enable(on: false)
      if isUserEditing == true {
          cell.enable(on: true)
      }
      return cell.contentView
  }
  </code></pre>
  
  <p>Here is where I change the <code>section image</code> when a user taps the section:</p>
  
  <pre><code>    @objc func handleTap(sender: UIButton) {
  
      sender.isSelected = !sender.isSelected
  
  }
  </code></pre>
  
  <p>When the user clicks the save <code>button</code>, I want the user input to be appended to those cells where the <code>section header</code> is selected. Here is that code:</p>
  
  <pre><code>@IBAction func save(_ sender: Any) {
      //VALIDATION
      guard  mealItemTextField.text != "", let item = mealItemTextField.text else {
          mealItemTextField.placeholder = "please enter an item"
          mealItemTextField.layer.borderWidth = 1
          mealItemTextField.layer.borderColor = UIColor.red.cgColor
          return
      }
      guard  priceTextField.text != "", let price = Double(priceTextField.text!) else {
          priceTextField.placeholder = "please enter a price"
          priceTextField.layer.borderWidth = 1
          priceTextField.layer.borderColor = UIColor.red.cgColor
          return
      }
          tableView.reloadData()
  }
  </code></pre>
  
  <p>Currently I am stuck on how to access all of the <code>indexes</code> of the <code>sections</code> that are selected(i.e. the ones that have a state of selected) Here are some screenshots to help visualize the program:
  <a href="https://i.stack.imgur.com/w2Vwy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w2Vwy.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/evLh8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/evLh8.png" alt="enter image description here"></a></p>
  
  <p><strong>P.S.</strong> Not sure if this is helpful but I populate the data with an <code>array</code> of <code>structs</code>. Here is that code:</p>
  
  <pre><code>func numberOfSections(in tableView: UITableView) -&gt; Int {
          return Data.userModels.count
  }
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          if Data.userModels[section].isExpandable {
              return Data.userModels[section].itemModels.count
          } else {
              return 0
      }
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
      if cell == nil {
          cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
      }
      cell?.textLabel?.text = Data.itemModels[indexPath.row].itemName
      return cell!
  }
  </code></pre>
  
  <p>Any help is appreciated, thanks!</p>