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
18
votes
3 answers

RxSwift modify tableview cell on select

I have a table view in my app. I generated the datasource for this table using following code struct ContactNameNumberBlockStatus { var contactThumbnail: Data? var contactName : String var contactNumber: String var blockStatus :…
LynAs
  • 6,407
  • 14
  • 48
  • 83
18
votes
2 answers

How to unsubscribe from Observable in RxSwift?

I want to unsubscribe from Observable in RxSwift. In order to do this I used to set Disposable to nil. But it seems to me that after updating to RxSwift 3.0.0-beta.2 this trick does not work and I can not unsubscribe from Observable: //This is what…
Marina
  • 1,177
  • 4
  • 14
  • 27
18
votes
3 answers

Using retryWhen to update tokens based on http error code

I found this example on How to refresh oauth token using moya and rxswift which I had to alter slightly to get to compile. This code works 80% for my scenario. The problem with it is that it will run for all http errors, and not just 401 errors.…
tskulbru
  • 2,336
  • 1
  • 20
  • 38
18
votes
6 answers

Two way binding in RxSwift

I read the two way binding operator in sample code of RxSwift. func <-> (property: ControlProperty, variable: Variable) -> Disposable { let bindToUIDisposable = variable.asObservable() .bindTo(property) let bindToVariable =…
leizh00701
  • 1,893
  • 5
  • 21
  • 32
17
votes
1 answer

rxswift bind(onNext: VS subscribe(onNext:

I have 2 questions: What difference between 'bind(onNext:' and 'subscribe(onNext:'? struct Info { var index: Int? var data: String? } let infoData: BehaviorRelay = BehaviorRelay(value: Info()) var osInfo: Observable {…
dh0rmfpdlxm
  • 301
  • 1
  • 3
  • 16
17
votes
1 answer

What is the difference between .subscribe and .drive

I am quite new in Reactive Programming, Here is what I'm trying .drive searchController.rx.text .asDriver() .drive(onNext: { (element) in print(element) }).disposed(by:…
Trool Destroyer
  • 207
  • 3
  • 8
17
votes
2 answers

How to select CollectionView cell in RxSwift

I need to select the item at specific index in collection view using RxSwift.This method is not working fine. collectionView.rx.modelSelected(SearchResult.self).subscribe(onNext:{ menuItem in }).addDisposableTo(disposeBag) Can anybody help?
Mehreen
  • 501
  • 3
  • 6
  • 11
17
votes
1 answer

How to manually send next signal to a observable in RxSwift?

I create an observable using the following code: let disposeBag = DisposeBag() let myJust = { (element: String) -> Observable in return Observable.create { observer in observer.on(.next(element)) …
leizh00701
  • 1,893
  • 5
  • 21
  • 32
17
votes
2 answers

Emit an event manually in RxSwift

I'm a newbie in RxSwift and need a very basic help. Assump that I have an Observable and subscribe it like this. let source: Observable = Observable.create { [weak self] observer in guard let _ = self else { …
dummy307
  • 193
  • 1
  • 2
  • 6
16
votes
3 answers

How to set RxTimeInterval for debounce in RxSwift?

Unable to set Rxtimeinterval for debounce in rxswift. My code is below. I got this error message "Cannot convert value of type 'Double' to expected argument type 'RxTimeInterval' (aka 'DispatchTimeInterval')" searchBar .rx.text // Observable…
Bikash Maharjan
  • 163
  • 1
  • 1
  • 4
16
votes
1 answer

Input parameter to closure in Swift with brackets

I am going through the following tutorial on RxSwift: http://adamborek.com/thinking-rxswift/ and having trouble understanding the following pattern: searchBar.rx.text.orEmpty ------------> .flatMap { [spotifyClient] query in …
Nikita Vlasenko
  • 4,004
  • 7
  • 47
  • 87
16
votes
3 answers

RxSwift - withLatestFrom combining values from both observables

I want to achieve result like this: L -1-2-3------4------5-6-7-8---- R ---------A------B----------C-- O ---------A3-----B4---------C8 So basically something like withLatestFrom but combining values from both observables (like combine latest). I…
Wujo
  • 1,845
  • 2
  • 25
  • 33
16
votes
1 answer

Simple timer with rxSwift

I'm trying to reproduce a simple timer with RxSwift. I have a pause/play button only that works for pause and resume. gameTimer = Observable.interval(1, scheduler: MainScheduler.instance) .subscribeNext({ sec -> Void…
jerrygdm
  • 450
  • 1
  • 7
  • 22
16
votes
2 answers

Proper usage of RxSwift to chain requests, flatMap or something else?

First of all, I'm new to rxswift so I guess the answer is obvious however at the moment I can't find solution by myself. I have two functions: func downloadAllTasks() -> Observable<[Task]> func getTaskDetails(taskId: Int64) ->…
Wujo
  • 1,845
  • 2
  • 25
  • 33
15
votes
2 answers

What is the difference between PublishSubject and PublishRelay in RxSwift?

I am new to RxSwift programming. I am confused between the two while coding. Which one should be used to store datasource of table and how to decide that ?
Emtiyaj Ali
  • 180
  • 1
  • 6
  • 13