How to convert ReplaySubject to string?

Viewed 35

I have an observable called email

var email = ReplaySubject<String>.create(bufferSize: 1)

how can I get direct value from it?

like user.email = email.value?

1 Answers

subjects are acting both as observables and observers so you have to both send and receive from them

var email = ReplaySubject<String>.create(bufferSize: 1)
            
email.on(.next("john@somecompany.com"))
            
email.on(.next("smith@somecompany.com"))

let subscriptionOne = email.subscribe(onNext: { string in
    print(string)
})
Related