Skip to content

Instantly share code, notes, and snippets.

@MrSmart00
Created June 4, 2020 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrSmart00/71479909beb6aa6dd60c3028c6086055 to your computer and use it in GitHub Desktop.
Save MrSmart00/71479909beb6aa6dd60c3028c6086055 to your computer and use it in GitHub Desktop.
PublishRelay with Property Wrapper
import Foundation
import RxSwift
import RxCocoa
@propertyWrapper
struct WrappedPublishRelay<Value> {
private let value: AnyObserver<Value>
private let observable: Observable<Value>
init(_ relay: PublishRelay<Value> = .init()) {
value = .init {
guard case let .next(value) = $0 else {
return
}
relay.accept(value)
}
observable = relay.asObservable()
}
var wrappedValue: AnyObserver<Value> {
return value
}
var projectedValue: Observable<Value> {
return observable
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment