Skip to content

Instantly share code, notes, and snippets.

@max6363
Created January 20, 2022 13:01
Show Gist options
  • Save max6363/357215c6d0ea578fbeeaaed52edc9fee to your computer and use it in GitHub Desktop.
Save max6363/357215c6d0ea578fbeeaaed52edc9fee to your computer and use it in GitHub Desktop.
class AgreementFormVC: UIViewController {
@Published var isNextEnabled: Bool = false
private var switchSubscriber: AnyCancellable?
@IBOutlet private weak var acceptAgreementSwitch: UISwitch!
@IBOutlet private weak var nextButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Save the Cancellable Subscription
switchSubscriber = $isNextEnabled
.receive(on: DispatchQueue.main)
.assign(to: \.isEnabled, on: nextButton)
}
@IBAction func didSwitch(_ sender: UISwitch) {
isNextEnabled = sender.isOn
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment