Created
January 20, 2022 13:04
-
-
Save max6363/66062f6c2f9ef51dac9d0d4e00596c0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AgreementFormVC: UIViewController { | |
@Published var isNextEnabled: Bool = false | |
// private var switchSubscriber: AnyCancellable? | |
private var subscribers = Set<AnyCancellable>() // ← set of all subscriptions | |
@IBOutlet private weak var acceptAgreementSwitch: UISwitch! | |
@IBOutlet private weak var nextButton: UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Save the Cancellable Subscription | |
$isNextEnabled | |
.receive(on: DispatchQueue.main) | |
.assign(to: \.isEnabled, on: nextButton) | |
.store(in: &subscribers) // ← storing the subscription | |
} | |
@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