Last active
July 19, 2019 03:16
-
-
Save daltonclaybrook/d42dffe77122364802720cc4155567a2 to your computer and use it in GitHub Desktop.
A Swift property wrapper which conforms to Publisher and emits before the wrappedValue has been set
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 | |
@propertyWrapper | |
struct NextValue<Output> { | |
typealias Failure = Never | |
typealias Publisher = AnyPublisher<Output, Never> | |
var wrappedValue: Output { | |
willSet { | |
subject.send(newValue) | |
} | |
} | |
var projectedValue: Publisher { | |
subject.eraseToAnyPublisher() | |
} | |
private let subject = PassthroughSubject<Output, Never>() | |
init(initialValue: Output) { | |
self.wrappedValue = initialValue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: