Created
March 25, 2025 12:45
-
-
Save hhhello0507/c59f8a6a506001d5700512394c2de735 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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