UISwitch Value Change Listener : Swift

This post was originally posted at https://agrawalsuneet.github.io/blogs/uiswitch-value-change-listener-swift/ and reposted on Medium on 13th April 2022.
  1. target of Any type which is nullable
  2. action of Selector type
  3. controlEvents of UIControl.Event
//swift code in viewcontrollerself.switch.addTarget(self, action: #selector(onSwitchValueChanged(_:)), for: .valueChanged) @objc private func onSwitchValueChanged(_ switch: UISwitch) {
//do something here
}
@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes
//MARK: - UISwitch Extension
extension UISwitch {
func setOnValueChangeListener(onValueChanged :@escaping () -> Void){

}
}

Please continue reading at https://agrawalsuneet.github.io/blogs/uiswitch-value-change-listener-swift/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store