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
8
votes
1 answer

RxSwift Build an Observable based on a Variable

I am trying to build an Observable which would output a value based on the value of a Variable. Something like that: let fullName = Variable("") let isFullNameOKObs: Observable isFullNameOKObs = fullName .asObservable() …
t4ncr3d3
  • 615
  • 1
  • 8
  • 17
8
votes
2 answers

How to map RxSwift Observable and Result

I have a quick question: I have a network request that returns Observable>, let’s call it requestToken if this request succeeds, I want to use the String (token) to do another request that returns…
Rodrigo Ruiz
  • 4,248
  • 6
  • 43
  • 75
8
votes
3 answers

How to show/hide the progressHUD, with MVVM and RxSwift in swift

I'm beginning with MVVM in order to well separate logic code from the view. But I have some concern about where to put the progressHUD related code when tapping a button that makes a request. Before, I used to do that: //Before @IBAction func…
user3620372
  • 187
  • 1
  • 9
8
votes
3 answers

RxSwift and UICollectionView Header

I'm using RxSwift with my UIViewController that contains a UICollectionView. I have tried to add a header to my collection view but this is never called: func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind:…
alexxjk
  • 1,681
  • 5
  • 18
  • 30
8
votes
1 answer

RxSwift: using rx_refreshing for uirefreshcontrol

I am using the UIRefreshControl + Variable binding to reload data. It is working, however, the following feels wrong to me: 1) I know there is a rx_refreshing variable in the RXCocoa extension, but I am unable to get it to work in this context. 2) I…
meow
  • 27,476
  • 33
  • 116
  • 177
8
votes
1 answer

is it safe to use [unowned self] in RxSwift Drivers?

example: tapGestureRecognizer.rx.event.asDriver() .drive(onNext: { [unowned self] _ in self.view.endEditing(true) }) .disposed(by: disposeBag) since the disposeBag is controlled by self, I would assume yes?
amleszk
  • 6,192
  • 5
  • 38
  • 43
8
votes
4 answers

RxSwift unwrap optional handy function?

Currently I have created a function unwrapOptional to safely unwrap the optional input in the stream. func unwrapOptional(x: Optional) -> Observable { return x.map(Observable.just) ?? Observable.empty() } let aOpt:…
LoGary
  • 322
  • 2
  • 3
  • 13
8
votes
1 answer

Proper way to dispose of a disposable within an observable

I have an HTTPService which returns an Observable. My goal is to compose that service into another service, ServiceA which transforms that data for my use case. Using Observable.create in RxSwift 2.0.0-rc.0 in ServiceA it's straight forward…
AJ Venturella
  • 4,742
  • 4
  • 33
  • 62
8
votes
2 answers

RxSwift: enable/disable button based on textfields are not empty

I have to enable a button based on the characters count on two textfields using RxSwift @IBOutlet weak var userTextField: UITextField! @IBOutlet weak var passwordTextField: UITextField! @IBOutlet weak var buttonToEnableDisable: UIButton! var…
Godfather
  • 4,040
  • 6
  • 43
  • 70
8
votes
2 answers

Using RxSwift, How To Enable UIButton Based on Valid Text?

In RxSwift/RxCocoa 2.0.0- beta 3, I have a ViewModel with: let someString = Variable("") func isValidSomeString() -> Observable { if someString.value.characters.count == 0 { return just(false) } return just(true) } I…
finneycanhelp
  • 9,018
  • 12
  • 53
  • 77
7
votes
2 answers

How to synchronously refresh an access token using Alamofire + RxSwift

I have this generic fetchData() function in my NetworkManager class that is able to request make a authorised request to the network and if it fail (after a number of retries) emits an error that will restart my app (requesting a new login). I need…
chr0x
  • 1,151
  • 3
  • 15
  • 25
7
votes
1 answer

Escaping closure captures mutating 'self' parameter

I'm trying to subscribe to an observable generated by a combineLatest, after flatMap. If I'm running this code in a struct I get this error: Escaping closure captures mutating 'self' parameter If I change to a class the error does not occurs. I…
chr0x
  • 1,151
  • 3
  • 15
  • 25
7
votes
2 answers

Binding a SwiftUI Button to AnySubscriber like RxCocoa's button tap

I use the following UIViewController and RxSwift/RxCocoa based piece of code to write a very simply MVVM pattern to bind a UIButton tap event to trigger some Observable work and listen for the result: import UIKit import RxSwift import…
JAHelia
  • 6,934
  • 17
  • 74
  • 134
7
votes
3 answers

countdown timer by `RxSwift`

I need a thirty-second time counter with RxSwift. This is a duplicate question but there is no clear answer to the questions
Behzad Moulodi
  • 147
  • 2
  • 11
7
votes
1 answer

How to implement shouldChangeTextIn the RxSwift way

Is there a way to implement the shouldChangeTextIn UITextView's delegate method in RxSwift way? My goal is to limit the text input of the user. I just have this: self.textView.rx.text .orEmpty .scan("") { (previous, new) ->…
Glenn Posadas
  • 12,555
  • 6
  • 54
  • 95