Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created November 17, 2024 20:01
Show Gist options
  • Save laevandus/a8e46aeead1ee58183006cd1a01dec2c to your computer and use it in GitHub Desktop.
Save laevandus/a8e46aeead1ee58183006cd1a01dec2c to your computer and use it in GitHub Desktop.
public extension Publisher where Self.Failure == Never {
func assignWeakly<Root>(to keyPath: ReferenceWritableKeyPath<Root, Self.Output>, on object: Root) -> AnyCancellable where Root: AnyObject {
return 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