Skip to content

Instantly share code, notes, and snippets.

@hhhello0507
Created March 25, 2025 12:45
Show Gist options
  • Save hhhello0507/c59f8a6a506001d5700512394c2de735 to your computer and use it in GitHub Desktop.
Save hhhello0507/c59f8a6a506001d5700512394c2de735 to your computer and use it in GitHub Desktop.
import Combine
import SwiftUI
public extension Publisher {
func ignoreError() -> AnyPublisher<Output, Never> {
return self.catch { _ in
Empty<Output, Never>()
}
.eraseToAnyPublisher()
}
func silentSink() -> AnyCancellable {
return self.sink { _ in } receiveValue: { _ in }
}
func silentSink(in set: inout Set<AnyCancellable>) {
self.silentSink().store(in: &set)
}
}
// Allow to assign Optional value
public extension Publisher where Failure == Never {
func assign<Root: AnyObject>(to path: ReferenceWritableKeyPath<Root, Output?>, on instance: Root) -> Cancellable {
sink { instance[keyPath: path] = $0 }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment