Skip to content

Instantly share code, notes, and snippets.

@marcbaldwin
Created June 24, 2021 10:07
Show Gist options
  • Save marcbaldwin/21ef54d74ec096199dbe3e5ce687ecc1 to your computer and use it in GitHub Desktop.
Save marcbaldwin/21ef54d74ec096199dbe3e5ce687ecc1 to your computer and use it in GitHub Desktop.
RxSwift RxRelay Property Wrapper
import RxRelay
import RxSwift
@propertyWrapper
final class RxRelayProperty<Value> {
var wrappedValue: Value {
get { relay.value }
set { relay.accept(newValue) }
}
var projectedValue: Observable<Value> {
relay.asObservable()
}
let relay: BehaviorRelay<Value>
init(wrappedValue: Value) {
relay = BehaviorRelay(value: wrappedValue)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment