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
10
votes
2 answers

RxSwift: What is the best practice to use DisposeBag?

Now I need to change the app theme(colors) based on configuration API, So I am using RxCocoa, RxSwift frameworks to create observable on each view controller to apply a new theme on the app. My question is what is the best practice for using…
Moayad Al kouz
  • 1,342
  • 1
  • 9
  • 19
10
votes
2 answers

RxSwift replacement shouldChangeCharactersInRange

I want use UITextfield with RxSwift. My goal is allowing/not input character in User keyboard and removing character from copy paste, I need handle UITextfield's delegate "shouldChangeCharactersInRange" with RxSwift. How to implement with…
David Sujarwadi
  • 205
  • 2
  • 10
10
votes
2 answers

RXSwift, Reentrancy anomaly was detected

I'm beginner in RXSwift, and i have problem with my code I have code: let dartScore = PublishSubject() dartScore.asObservable() .scan(501) { intermediate, newValue in let result = intermediate -…
Seishin Okigaru
  • 391
  • 1
  • 4
  • 13
10
votes
3 answers

RxSwift — background task without freezing UI

I would like to do some heavy lifting in the background thread of my iOS app and NOT freeze the UI while it is being performed. What I try is: self.someDisposable = heavyLiftingFuncReturningObservable() …
dobranoc
  • 465
  • 1
  • 4
  • 17
10
votes
1 answer

RxSwift multiple subscriptions to one observable

I understand that if I want to have multiple subscriptions to one observable I need to use .share() operator, but I do not understand why exactly? I looking for some example based on local data (not network) to demonstrate what is the difference…
Mr. A
  • 704
  • 1
  • 7
  • 16
10
votes
2 answers

RxSwift: Mapping a completable to single observable?

I am trying to do a couple of actions in sequence, using RxSwift and am unsure how to get it working. The problem is returning a Single observable, where the success/error depends on whether a Completable call succeeds or fails. My code attempt…
Yasir
  • 2,312
  • 4
  • 23
  • 35
10
votes
3 answers

What is the RxSwift 3.0 equivalent to AnonymousDisposable from RxSwift 2.x?

The ReactiveX.io documentation uses AnonymousDisposable, which was in RxSwift 2.x, but is an unresolved identifier in RxSwift 3.0. What should I use instead? let source = Observable.create { observer in for i in 1...5 { observer.on(.Next(i)) …
DavidA
  • 3,112
  • 24
  • 35
10
votes
2 answers

Handling Network error in combination with binding to tableView (Moya, RxSwift, RxCocoa)

I am currently using Moya to make my network requests. I have implemented the following from one of the example projects @ https://github.com/DroidsOnRoids/RxSwiftExamples#tutorials Below I have set up restaurantSearch so that when someone enters…
pls
  • 1,522
  • 2
  • 21
  • 41
10
votes
2 answers

RxSwift propagating a value through a chain of flatMaps

So I have some RxSwift code where I want to perform a chain of asynchronous operations, all composed using observables. flatMap is the way to do this, and it works great, however it doesn't seem to be able to pass variables down the chain that I can…
Orion Edwards
  • 121,657
  • 64
  • 239
  • 328
10
votes
1 answer

RxSwift Using Variables Correctly

I am trying to convert a project to use RxSwift and MVVM. I have a service that syncs a list of data from Parse on every app launch and I basically want to make sure I am taking the correct approach. What I have done is made a Variable subject and…
Manny
  • 1,682
  • 1
  • 14
  • 13
10
votes
1 answer

RxSwift - UILabel field not being updated when UITextField updated programmatically

I'm just learning RxSwift and have a simple example that I'm not sure why it is not working. I have a text field and a label field. ANY time the text field changes, I'd like the label field to be updated. If I type in the text field, everything…
dfrobison
  • 203
  • 2
  • 11
9
votes
1 answer

How to hide the third-party calls in the call stack in Xcode

When I work with Realm or RxSwift and there's an exception, I get these giant call stacks that I don't care about, and have to find the one or two lines that are my code. I'd like to only show symbols on the call stack that are from within the…
Marty
  • 5,926
  • 9
  • 53
  • 91
9
votes
1 answer

Changing the text of a UITextField does not trigger the rx.text binder

I have a UITextField called commentField and I create an Observable like this: let isCommentFieldValid = self.commentField.rx.text.orEmpty.map({ !$0.isEmpty }) This observable determines whether a button is enabled or not. The problem is that…
Kévin
  • 850
  • 7
  • 13
9
votes
2 answers

RxSwift how to append to BehaviorSubject<[]>

Since Variable is deprecated in RxSwift 4, what is the equivalent way for BehaviorSubject to do the following? let observable = Variable<[Int]>([]) observable.value.append(1)
Jack Guo
  • 3,959
  • 8
  • 39
  • 60
9
votes
3 answers

How to write height for row in RxSwift?

I want to convert the below code into RxSwift. And also please help me how to write button Action code in RxSwift. ReactiveCocoa or RxSwift Which one is better to use in swift3? func tableView(_ tableView: UITableView, numberOfRowsInSection section:…
Bharath
  • 125
  • 1
  • 1
  • 7