You may see share(replay:1)
using BehaviorRelay on RxSwift.
let relay=RxCocoa.BehaviorRelay<String>(value:"")
variable:RxSwift.Observable<String>{
return relay
.observeOn(MainScheduler.instance)
.share(replay:1)
// ↑ Here
}
I think BehaviorRelay will return the current value when subscribed, but what does it mean to write share(replay:1)
?
Reference
[RxSwift] I summarized Behavior Relay and Publish Relay
I've been using Rx for years, but I've never seen a code with .share(replay:1) on Behavior Relay🤔
.share(replay:1) is used for hot conversion (basically), but it doesn't make sense because the Behavior Relay just before is hot...
However, as the comment says, if
variable:RxSwift.Observable<String>{
return relay
.map {$0.uppercased()}
.share(replay:1)
If there is an operator who converts to cold just before, even if you subscribe only once, it will be meaningful considering the future!
568 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
897 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
568 Who developed the "avformat-59.dll" that comes with FFmpeg?
601 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.