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

commented Jan 25, 2016

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

@sergdort

This comment has been minimized.

Copy link
Collaborator

commented Jan 25, 2016

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

This comment has been minimized.

Copy link
Contributor

commented Jan 27, 2016

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

@DuckDeck

This comment has been minimized.

Copy link
Author

commented Jan 27, 2016

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 .

@DuckDeck DuckDeck closed this Jan 27, 2016

@thanegill

This comment has been minimized.

Copy link
Contributor

commented Jan 27, 2016

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

@AleksandarSavic95

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Collaborator

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
Projects
None yet
5 participants
You can’t perform that action at this time.