Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get the current value of the Observable<T> type without subscribe func #435

Closed
DuckDeck opened this issue Jan 25, 2016 · 6 comments

Comments

@DuckDeck
Copy link

As the title. So how can I fetch the current value(T) of the Observable type without subscribe func

@sergdort
Copy link
Contributor

Hi, @DuckDeck as far as I know current value u can get only within Variable<T>

To clarify the concept of observable I would sagest you to take a look on this video

@thanegill
Copy link
Contributor

There is no value to an Observable until you subscribe. What's your use case?

@DuckDeck
Copy link
Author

Here is the instance: I can get a Observable from UITextView txt:
let observableTxt = txt.rx_text
so how can I convert observableTxt to txt.text with out subscribe func? I mean to fetch the current value from Observable .

@thanegill
Copy link
Contributor

The observable .rx_text is just a sequence of changes to the .text field so the "current" value is the same as .text.

@AleksandarSavic95
Copy link

AleksandarSavic95 commented Oct 1, 2018

I know the issue is closed, but for anyone still wondering, here it is:

...
let currentValue;
myObservableFunction().subscribe(v => currentValue = v);
// use currentValue as You wish

Note This will work if the myObservableFunction returns the observable immediately.
If the called function (the one You are subscribing to) is a longer-lasting operation, You should pass the retrieved value to a callback function:

myObservableFunction().subscribe(v => myCallback(v));

I know You asked for a solution without the subscribe function, but this is the way to go.

@freak4pc
Copy link
Member

freak4pc commented Oct 2, 2018

Your code seems to be RxJS, not RxSwift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants