Skip to content

Instantly share code, notes, and snippets.

@gdavis
Created February 10, 2021 18:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gdavis/3c026811777c6922914335abadfa60cf to your computer and use it in GitHub Desktop.
Save gdavis/3c026811777c6922914335abadfa60cf to your computer and use it in GitHub Desktop.
Combine assign method without the memory leak
extension Publisher where Self.Failure == Never {
public func assignNoRetain<Root>(to keyPath: ReferenceWritableKeyPath<Root, Self.Output>, on object: Root) -> AnyCancellable where Root: AnyObject {
sink { [weak object] (value) in
object?[keyPath: keyPath] = value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment