Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active April 8, 2020 21:11
Show Gist options
  • Select an option

  • Save jasdev/900a9a74b3ea678590dcafe5582fa146 to your computer and use it in GitHub Desktop.

Select an option

Save jasdev/900a9a74b3ea678590dcafe5582fa146 to your computer and use it in GitHub Desktop.
Example `assign` retain cycle.
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