title: How to call a function when the index for you SegmentedControl is changed
body: <p>I'm trying to call a fucntion &quot;indexChanged&quot; when my UISegmentedControl changes index. I'm using the .addAction function that is apart of this class. I receive this warning: &quot;No method declared with Objective-C selector 'indexChanged:'&quot;, yet even when I add a @objc tag next to the &quot;indexChanged&quot; function, I receive more errors.</p>
  <p>Is there an alternative way to call a function when the SegementedControl index changes? Some code is below:</p>
  <pre><code>let items = [&quot;Donors&quot;, &quot;Cars&quot;]
  let controller = UISegmentedControl(items: items)
      controller.selectedSegmentIndex = 0
  
      let frame = UIScreen.main.bounds
      controller.frame = CGRect(x: frame.maxX - 135, y: frame.minY + 10,
                              width: frame.width - 250, height: frame.height*0.03)
  
  
      controller.addTarget(self, action: &quot;indexChanged:&quot;, for: .valueChanged)
      
      
      map.addSubview(customSC) // map is a UIKit Map
  
  
  
  func indexChanged(_ sender: UISegmentedControl) {
      if sender.selectedSegmentIndex == 0 {
          print(&quot;Select 0&quot;)
      } else if sender.selectedSegmentIndex == 1 {
          print(&quot;Select 1&quot;)
      }
  }
  </code></pre>
  <p>Thanks a bunch!</p>