Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woodycatliu/9ccb4d87a793c6a5c0894ba3d2ff935e to your computer and use it in GitHub Desktop.
Save woodycatliu/9ccb4d87a793c6a5c0894ba3d2ff935e to your computer and use it in GitHub Desktop.
CurrentValueSubject init from AnyPublisher and avoid retain cycle
import Combine
extension CurrentValueSubject where Failure == Never {
convenience init(with publisher: AnyPublisher<Output, Failure>, value: Output) {
self.init(value)
publisher.receive(subscriber: AnySubscriber(self))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment