title: How to allow user to turn on ONLY a single uiSwitch that is built programmatically and store data of the switch
body: <p>I have a programmatically built uiswitch in my <code>car register tableview</code> that when the user switches it on for the car of their choice, the boolean is saved and stored in core data and the car brand will be displayed in a different view controller. </p>
  
  <p>Question:
  How can I make it that the user can only turn on ONE switch and how can i save that data (Car name) when the switch is turned on?</p>
  
  <p>Code:</p>
  
  <pre><code>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
      let cellS = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TableViewCell
  
      //here is programatically switch make to the table view
  
      switchView.setOn(false, animated: true)
      switchView.tag = indexPath.row // for detect which row switch Changed
  //        switchView.addTarget(self, action: #selector(self.switchChanged(_:)), for: .valueChanged)
      cellS.accessoryView = switchView
  
      if indexPath.row != 0 {
          switchView.isEnabled = true
          UserDefaults.standard.set(switchView.isOn, forKey: "CarSwitch")
  </code></pre>
  
  <p>This is my attempted code:</p>
  
  <pre><code>    if switchView.isSelected {
              UserDefaults.standard.set(indexPath.row, forKey: "usethiscar")
          }
  
      }
  
      if tableView == table1 {
          let cell = table1.dequeueReusableCell(withIdentifier: "Cell")
  
          let row = indexPath.row
          cell?.textLabel?.text = table1Data[row]
  
          return cell!
      }
  
      return UITableViewCell()
  } 
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Jm34j.png" rel="nofollow noreferrer">This is how it looks like</a></p>
  
  <p><a href="https://i.stack.imgur.com/H2F3T.png" rel="nofollow noreferrer">This is when 'Add car is' pressed</a></p>
  
  <p><a href="https://i.stack.imgur.com/tcSez.png" rel="nofollow noreferrer">This is not supposed to happen when two switches are on</a></p>