Questions tagged [rx-swift]

RxSwift's intention is to enable easy composition of asynchronous operations and event/data streams. Use this tag only for questions that are specific to the RxSwift - Reactive Programming paradigm, or those that require code in the language. Use the related tags [ios], [osx], [apple-watch], [cocoa-touch], and [cocoa] for (language-agnostic) questions about the platforms or frameworks.

About Rx and RxSwift

Rx is a generic abstraction of computation expressed through Observable<Element> interface.

RxSwift is a Swift version of Rx.

It tries to port as many concepts from the original version as possible, but some concepts were adapted for more pleasant and performant integration with iOS/macOS environment.

Cross platform documentation can be found on ReactiveX.io.

Like the original Rx, its intention is to enable easy composition of asynchronous operations and event/data streams.

KVO observing, async operations and streams are all unified under abstraction of sequence. This is the reason why Rx is so simple, elegant and powerful.


Resources

2149 questions
25
votes
4 answers

How do you get a signal every time a UITextField text property changes in RxSwift

How do you get a signal from programmatically made changes to UITextField text property? By using rx.text only reports a signal when the user input the text by keyboard. If you set textField.text programmatically, the signal doesn't fire. This is…
Ethan Cheung
  • 261
  • 1
  • 3
  • 6
25
votes
2 answers

UITextField binding to ViewModel with RxSwift

I am willing to use RxSwift for MVVM binding between model values & view controllers. I wanted to follow this realm.io tutorial, but the binding has apparently changed since then, and the sample code does not compile. Here is the sample code, where…
satellink
  • 499
  • 2
  • 5
  • 10
24
votes
1 answer

Is there a way to not trigger the init value of the Variable?

See below code. class ViewController4: UIViewController { var disposeBag = DisposeBag() let v = Variable(0) override func viewDidLoad() { super.viewDidLoad() v.asObservable() .subscribe(onNext: { print($0)…
Owen Zhao
  • 3,205
  • 1
  • 26
  • 43
24
votes
3 answers

Manually disposing a DisposeBag in RxSwift

I want to cancel a request and one of the ways is to manually remove the disposable bag. .addDisposableTo(disposeBag) As I have the disposeBag object, is there a good way to cancel the request other than that I mentioned above?
robertsan
  • 1,591
  • 3
  • 14
  • 26
24
votes
8 answers

Observable Current and Previous Value

I have a Variable which is an array of enum values. These values change over time. enum Option { case One case Two case Three } let options = Variable<[Option]>([ .One, .Two, .Three ]) I then observe this variable for changes. The…
23
votes
2 answers

what is difference between do(onNext:) and subscribe(onNext:)?

I'm new in RxSwift, I don't understand what is difference between do(onNext:) and subscribe(onNext:). I google it but did't found good resources to explain the difference.
behrad
  • 596
  • 1
  • 5
  • 19
23
votes
5 answers

Is there a preferred type for an Observable with no need for a value in Next events?

I have an Observable which is only used for triggering flatMap/map. So I only ever need the Next event and never a value. I could use my own concept for such a trash value, but I'm wondering if there's an RxSwift convention for it. Here's what I'm…
solidcell
  • 7,639
  • 4
  • 40
  • 59
23
votes
1 answer

Proper way to dispose a one-off observable in RxSwift

I have an observable that I only want to kick off once. The docs say: Using dispose bags or takeUntil operator is a robust way of making sure resources are cleaned up. We recommend using them in production even if the sequences will terminate in…
Ying
  • 1,944
  • 5
  • 24
  • 38
22
votes
2 answers

Rxswift observable bind(to:) vs subscribe(onNext:)

Sorry. I am confused what is binding in Rxswift. As far as I know, observable won't produce value unless a observer subscribed on it, e.g myObservable.subscribe(onNext: {}). But when I read the follow line of code: // in…
bufferoverflow76
  • 767
  • 1
  • 8
  • 23
20
votes
2 answers

RxSwift merge different kind of Observables

How should I merge 2 different types of Observables in RxSwift? For example: var a: Observable var b: Observable Observable.of(a,b).merge() is not possible because of type parameter difference.
Swift Hipster
  • 1,604
  • 3
  • 16
  • 24
20
votes
5 answers

Confusion about flatMapLatest in RxSwift

I learn the sample code in RxSwift. In the file GithubSignupViewModel1.swift, the definition of validatedUsername is: validatedUsername = input.username //the username is a textfiled.rx_text .flatMapLatest { username ->…
leizh00701
  • 1,893
  • 5
  • 21
  • 32
20
votes
1 answer

RxSwift - Misundestanding some concept

I'm a very beginner with RxSwift and I'm trying to begin with a simple login screen. So I have 2 text fields and a login button, which is bind to a PublishSubject so every time I tap the button, I'll send a network request to perform…
Yaman
  • 3,949
  • 4
  • 38
  • 60
19
votes
1 answer

RxSwift/RxCocoa: prevent UITextField from having more than ... characters

I would like to have a UITextField configured with RxSwift/RxCocoa so that it only contains up to ... characters. I do not want to use the UITextFieldDelegate for this but would love to achieve this with RxSwift/RxCocoa. Is there a way to do this?
swalkner
  • 16,679
  • 31
  • 123
  • 210
18
votes
3 answers

What are the differences between observable and subject in rxSwift

What are the differences between observable and subject. When I define a observable type variable. It can emit onNext,onComplete,onDispose. However subject can do the same. When should I use observable and in what case should I use subject?
Dean Lee
  • 781
  • 2
  • 7
  • 13
18
votes
7 answers

How to import RxSwift in Playground of xcode?

I am trying to import rxswift in xcode playground by this: gem install cocoapods-playgrounds and after that pod playgrounds RxSwift But it is not happening. How to do it?
Istiak Morsalin
  • 10,621
  • 9
  • 33
  • 65