I have a UISwitch that is hooked to to rx. Whenever it's toggled an alertView is displayed. If ok is chosen, some stuff will happen, but if cancel is pressed, nothing will happen, and the UISwitch will remain in the same place, that is it's not toggled.
mySwitch.rx.controlEvent(.valueChanged).subscribe(onNext: { [weak self] _ in
guard let self = self else { return }
CustomAlertViewController.standardTwoButtonMessageAlert(title: self.mySwitch.isOn ? "Do you want to turn this on?" : "Do you want to turn this off?", msg: "hello", action: {
print("Doing stuff")
}, cancelAction: {
//SHOULD NOT TOGGLE
})?.present(animated: true, onView: UIApplication.topViewController())
}).disposed(by: disposeBag)
There is also the problem of the UISwitch already having been toggled when I reach cancelAction, meaning that it needs to be toggled back again. How do I toggle it back? And is there a way to prevent it from toggling at all so I can manage this manually inside the closures?