-
-
Save jasdev/900a9a74b3ea678590dcafe5582fa146 to your computer and use it in GitHub Desktop.
Example `assign` retain cycle.
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
| import Combine | |
| final class SomeViewModel: ObservableObject { | |
| // MARK: - Outputs | |
| @Published var someProperty = () /// (1) Using `Void` for sake of example. | |
| // MARK: - Private | |
| private var subscriptions = Set<AnyCancellable>() | |
| init() { | |
| somePublisher /// (2) of `Output` type `Void` and `Never`-valued `Failure`. | |
| .assign(to: \.someProperty, on: self) /// (3) Accidental `strong` catpture of `self`. | |
| .store(in: &subscriptions) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment