Created
March 28, 2021 13:45
-
-
Save gtokman/a43b8127f306b348bbfcd211206053ea to your computer and use it in GitHub Desktop.
Published - combine
This file contains hidden or 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
| // Create a new search subject with a default value | |
| final class ViewController: UIViewController { | |
| // Published subject initialized to zero | |
| @Published var buttonTapSubject: Int = 0 | |
| var cancellables = Set<AnyCancellable>() | |
| let button = UIButton() | |
| let label = UILabel() | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| /* layout code removed for brevity */ | |
| // subscribe to button taps and assign value to label | |
| $buttonTapSubject | |
| .map{ String($0) } | |
| .assign(to: \.text, on: label) | |
| .store(in: &cancellables) | |
| } | |
| @objc func didTap() { | |
| buttonTapSubject += 1 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment