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
7
votes
4 answers

How to subscribe on the value changed control event of a UISwitch Using Rxswift

I want to use Rxswift and not IBActions to solve my issue below, I have a UISwitch and I want to subscribe to the value changed event in it, I usually subscribe on Buttons using this manner @IBOutlet weak var myButton: UIButton! myButton …
MhmdRizk
  • 1,591
  • 2
  • 18
  • 34
7
votes
4 answers

How to get which button is clicked in RxSwift

I have created a common action for an array of my button. I just want to get the which button is tapped. I have array of buttons like let buttons = [UIButton(), UIButton(), UIButton(),UIButton()]. let observable = Observable.of(buttons[0].rx.tap,…
Ravi Dhorajiya
  • 1,531
  • 3
  • 21
  • 26
7
votes
3 answers

RxSwift. Execute separate Observables sequently

I'm trying to achieve my Observables to execute only when previous Observable has completed. I can't use flatMap, because subscriptions can be called from different places, and this Observables is not connected with each other. To be specific: I…
KY1VSTAR
  • 395
  • 4
  • 16
7
votes
3 answers

RxSwift: Chain Completable to Observable

I'd like to chain a Completable to an observable element. After calling flatMap, onCompleted and onError callbacks don't seem to be called on subscription. var user = PublishRelay() func fetchUserInformation(_ userId: String) -> Completable…
juliancadi
  • 987
  • 1
  • 8
  • 23
7
votes
1 answer

RxSwift - how to chain observables sequentially

Assume I have array of Ints: var items = [1, 2, 3, 4, 5] and a function that takes Int argument and basing on it sends network request: func sendRequest(argument: Int) -> Observable { // sends network request ... } I want to send…
Wujo
  • 1,845
  • 2
  • 25
  • 33
7
votes
1 answer

How do I check for internet using Moya and RxSwift?

As far as I understand Alamofire is pulled in with built in Reachability, so my own handler would look something like: import Alamofire let reachabilityManager = NetworkReachabilityManager() reachabilityManager.listener = { status in switch status…
AMAN77
  • 6,218
  • 9
  • 45
  • 60
7
votes
1 answer

How to properly combine multiple Drivers with RxSwift?

I'm combining a viewDidAppear and filter Drivers with RxSwift. And they work great. But when I introduce a third Driver, it stops calling flatMapLatest on the latest combine. In my View Controller, I have these Drivers: let filter:…
nmdias
  • 3,888
  • 5
  • 36
  • 59
7
votes
2 answers

Custom UIControl subclass with RxSwift

I am creating a custom subclass of UIControl (I need to override its draw method) and I want to add RxSwift to bind its isSelected property to my model. So far so good. This works fine. My problem is how can I do to change the value isSelected…
t4ncr3d3
  • 615
  • 1
  • 8
  • 17
7
votes
0 answers

RxSwift UIBarButtonItem Tap Event Not Called

I have the following code and it DOES not call the Tap event. self.addNewItemBarButton.rx.tap.subscribe { print("button is clicked") // NOT GETTING CALLED! }.addDisposableTo(disposeBag) SOLUTION: …
john doe
  • 9,220
  • 23
  • 91
  • 167
7
votes
1 answer

How to replace UICollectionViewDelegateFlowLayout by a reactive(RxSwift) call?

Is there a way to replace the method func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize from the UICollectionViewDelegateFlowLayout protocol by…
Marcone
  • 855
  • 2
  • 8
  • 17
7
votes
3 answers

How to filter array of Observable element | RxSwift

I have a struct Person and person array as following struct Person { let name : String let age : Int } let personArray = [ Person(name : "Max", age : 32), Person(name : "Jones", age : 42), Person(name : "Other", age : 62) ] I…
Mahabub
  • 511
  • 2
  • 6
  • 16
7
votes
2 answers

Register two custom cells with RxSwift

I have a ViewController connect to a Xib file. In this Xib file I have a View, and inside this View, I have a TableView like so I also have LeftTableViewCell and RightTableViewCell which connected to another Xib files. Now I want to register…
Twitter khuong291
  • 11,328
  • 15
  • 80
  • 116
7
votes
1 answer

RxSwift - .subscribe vs .subscribeNext what is the difference?

What is the difference betweeen these two operators ? http://reactivex.io dont mention .subscribeNext at all.
Alexey K
  • 6,537
  • 18
  • 60
  • 118
7
votes
1 answer

Custom Error Response Handling with Moya + RxSwift

I'm using Moya with RxSwift for networking in an iOS app, and I'd like to be able to consume my API's custom error responses when my Observers get calls to onError. The API always returns error responses in the following JSON format: { "error":…
Scott Storch
  • 794
  • 3
  • 9
  • 16
7
votes
1 answer

Re-subscribing to an Observable after error

I feel like I'm beginning to get the hang of RxSwift - however I've just hit a roadblock. Here's an object I've built for a demo (I've simplified it before posting to SO). My issue is, when there's a network error during the upload process, all of…
jonlambert
  • 432
  • 7
  • 14