markst
Seems that subscriptions to publishers only work If a reference to the subscription is maintained.  Will this always be the case?
#4 · closed · 2 comments
Seems that subscriptions to publishers only work If a reference to the subscription is maintained.  Will this always be the case?
FYI here's my usage: ```swift import UIKit import Combine import Combinative class GameOverViewController: UIViewController { var retryTapped = PassthroughSubject<UIButton, Never>() // MARK: - Outlets @IBOutlet private weak var retryButton: UIButton! // MARK: - Privates private var retrySubscription: AnyCancellable? // MARK: - View Lifecycle override func viewDidLoad() { super.viewDidLoad() retrySubscription = retryButton.cmb.tap.subscribe(retryTapped) } } ``` ```swift var retrySubscriber: AnyCancellable? override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let gameOverViewController = segue.destination as? GameOverViewController { retrySubscriber = gameOverViewController.retryTapped.sink(receiveValue: { [unowned self] _ in self.performSegue(withIdentifier: "GameModeSelection", sender: nil) }) } } ``` Perhaps I'm taking the wrong approach? Seems like a lot of references have to be made for this kind of setup?...
Yes, You should store `subscriber` or use `store(by: cancellables)`. This approach is generally by combine frameworks.