Created
June 24, 2021 10:07
-
-
Save marcbaldwin/21ef54d74ec096199dbe3e5ce687ecc1 to your computer and use it in GitHub Desktop.
RxSwift RxRelay Property Wrapper
This file contains 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 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