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

What's the difference between throttle and debounce in Rxswift3.0?

I have seen a lot of blogs about throttle and debounce. Most of them said they are the same thing. But I get the different result form my example? Here is the example: let disposeBag = DisposeBag() Observable.of(1,2,3,4,5) .debounce(1,…
Longshihua
  • 395
  • 1
  • 3
  • 20
12
votes
2 answers

How to show collection view 3 columns in 1 row with RxSwift

Here is my code: import UIKit import RxSwift import RxCocoa import RxOptional class ViewController: UIViewController { @IBOutlet weak var collectionView: UICollectionView! let disposeBag = DisposeBag() override func viewDidLoad() { …
Twitter khuong291
  • 11,328
  • 15
  • 80
  • 116
12
votes
2 answers

Paginated API Calls with RxSwift

I am starting my first RxSwift project for an iOS app and learning about reactive programming. So far, the idea is quite simple, the user searches for films matching the search bar text, this fires a request that populates a UITableView with the…
Broco
  • 679
  • 1
  • 4
  • 16
12
votes
2 answers

When should we call addDisposableTo(disposeBag) in RxSwift?

We create a DisposeBag, and a Observable, subscribe the Observable and then addDisposableTo(disposeBag), I know when the DisposeBag is going to deinit, it will call dispose() to release resources otherwise it will lead memory leak. If the…
leizh00701
  • 1,893
  • 5
  • 21
  • 32
11
votes
2 answers

RxSwift: What is the usage difference between BehaviorSubject and BehaviorRelay?

I am aware that BehaviorRelay is replacing Variable, and both BehaviorSubject and BehaviorRelay starts with an initial value, and replays it or the latest value to the subscribers. What are the differences then? in which case you would use one over…
Alan Steiman
  • 412
  • 1
  • 4
  • 14
11
votes
2 answers

iOS RxSwift how to prevent sequence from being disposed on (throw error)?

I have a sequence made up of multiple operators. There are total of 7 places where errors can be generated during this sequence processing. I'm running into an issue where the sequence does not behave as I expected and I'm looking for an elegant…
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
11
votes
1 answer

How to use RxSwift Observable.interval?

I'm trying to emit a sequence on a ”pulse” at a given time interval. Totally new to everything Rx, but thought this would do it: import RxSwift let db = DisposeBag() _ = Observable.interval(1.0, scheduler: MainScheduler.instance) …
PEZ
  • 16,821
  • 7
  • 45
  • 66
11
votes
3 answers

RxSwift convert Observable to Observable

I am not so convinced with RxSwift yet, and it's really hard to cleat understanding. After reviewing different materials, I cant' still work and manipulate sequences. On the whole I have problem with type converting: Cannot convert return expression…
biloshkurskyi.ss
  • 1,358
  • 3
  • 15
  • 34
11
votes
2 answers

Return a completable in RxSwift without using a create block

I have a Completable being returned from a simple function. This is not an async call, so I just need to return a succcessful completion or error depending on a conditional (using Rx here so I can tie into other Rx usages): func exampleFunc() ->…
Yasir
  • 2,312
  • 4
  • 23
  • 35
11
votes
1 answer

Subscribe to last value after completed on RxSwift PublishSubject

I'm looking for something like this: let observable = PublishSubject() observable.onNext("1") observable.onCompleted() _ = observable.subscribeNext { s in print(s) } So I want to subscribe to the Observable after it has already been…
Rodrigo Ruiz
  • 4,248
  • 6
  • 43
  • 75
11
votes
1 answer

Merging two notification observers in RxSwift

I have this piece of code: let appActiveNotifications: [Observable] = [ NSNotificationCenter.defaultCenter().rx_notification(UIApplicationWillEnterForegroundNotification), …
Milan Cermak
  • 7,476
  • 3
  • 44
  • 59
11
votes
2 answers

RxSwift, how do I chain different observables

I am still a beginner in Reactive programming, and RxSwift in general. I want to chain two different operation. In my case I simply want to download a zip file from a web server, and then unzip it locally. I also want, at the same time to show the…
Punty
  • 910
  • 2
  • 11
  • 18
11
votes
1 answer

What does the following example code from RxSwift/RxCocoa do?

I'm trying to understand in detail .drive(resultsTableView.rx_itemsWithCellIdentifier("WikipediaSearchCell", cellType: WikipediaSearchCell.self)) { (_, viewModel, cell) in cell.viewModel = viewModel } from…
HBu
  • 559
  • 6
  • 18
10
votes
1 answer

swift package in two targets in Xcode causes duplicate symbols

I have two frameworks in my project, each of which depend on the same Swift package (in this case RxSwift, but I don't think that's important). To get the project to build I've had to include the same package in both targets (via the "Frameworks and…
deanWombourne
  • 38,189
  • 13
  • 98
  • 110
10
votes
2 answers

In RxSwift how can I set up a Subject to observe another Observable?

Let's say I have the following: let theSubject = PublishSubject() let theObservable = Observable.just("Hello?") How do I set the theSubject to observer theObservable? In RxSwift we say that a subject is an observer and can subscribe to…
Andrew Paul Simmons
  • 4,334
  • 3
  • 31
  • 39