Skip to content

Instantly share code, notes, and snippets.

@agrawalsuneet
Last active March 30, 2022 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agrawalsuneet/f08c850869a53d1f14378344337d82eb to your computer and use it in GitHub Desktop.
Save agrawalsuneet/f08c850869a53d1f14378344337d82eb to your computer and use it in GitHub Desktop.
Extension to UISwitch to add switch value change event in a clean way
//MARK: - UISwitch Extension
@available(iOS 14.0, *)
extension UISwitch {
func setOnValueChangeListener(onValueChanged :@escaping () -> Void){
self.addAction(UIAction(){ action in
onValueChanged()
}, for: .valueChanged)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment