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
1
vote
1 answer

How to display and recover from API errors in ViewController when using RxSwift

I'm trying to figure out how I can retry an API call at the ViewController layer when dealing with an RxSwift stream. I understand that I can either wrap my errors in an Element or I can return a stream Error. In either case, it's not at all clear…
Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106
1
vote
1 answer

What does the >- operator mean in RxSwift and where is it documented?

I've seen the >- operator in various code fragments involving RxSwift (e.g. https://github.com/ReactiveX/RxSwift/issues/35), but can't find any documentation on it. What does it mean? Here's an example: combineLatest(emailIsValid, passwordIsValid) …
Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106
1
vote
1 answer

Rxswift + Moya + Moya-ObjectMapper Error handling

I am using Moya and Moya-ObjectMapper with Rxswift to make network requests. My network request is below. let provider = RxMoyaProvider() requestHospitalButton.rx_tap .withLatestFrom(hospitalCode) .flatMapLatest { [unowned self]…
c8112002
  • 375
  • 3
  • 13
1
vote
1 answer

How to combine two observables in Reactive Extensions in order to paginate results?

I am trying to develop a pagination system in an iOS app using RxSwift. The use case is simple: the user can enter text in a search field and the app performs a request that is paginated. When he changes the value, a new request is performed on the…
obo
  • 1,652
  • 2
  • 26
  • 50
1
vote
1 answer

Long Polling with RxSwift

I want to make a simple long polling request with RxSwift which may be the similar to RxJava code below: api.loadHotels(searchRequest) .repeatWhen(obs -> observable.delay(3, TimeUnit.SECONDS)) .takeUntil(searchResponse ->…
Okhan Okbay
  • 1,374
  • 12
  • 26
1
vote
1 answer

Buffer Observable Until Another Observable Completes

I'm using RxSwift to wrap a mobile app's server sync process. I have an Observable that wraps a websocket connection and emits each message received as an Event. Similarly, I have an Observable that wraps an API…
Colin M
  • 13,010
  • 3
  • 38
  • 58
1
vote
1 answer

RxSwift: Need help using flatMap and reduce

I am writing a simple Diceware password generator to experiment with RxSwift. I am struggling with using flatMap and reduce in separate steps. Current code I have an observable wordCount that is bound to the UIStepper value and generate a new…
Yann Bodson
  • 1,634
  • 1
  • 17
  • 29
1
vote
1 answer

RxSwift PublishSubject of type Optional startWith nil

I'm trying to achieve the following: let reachedTopMostMessage = PublishSubject() reachedTopMostMessage.startWith(nil).subscribeNext { (_) in // } But the compiler complains with this error: 'Int?' (aka 'Optional') is not convertible to…
Swift Hipster
  • 1,604
  • 3
  • 16
  • 24
1
vote
1 answer

Subscription using Driver with RxSwift

I have a question about RxSwift and the use with Driver. I tried only with this pattern loginButton.rx_tap .doOn({[unowned self] _ in self.loginButton.enabled = false }) .debug() …
jerrygdm
  • 450
  • 1
  • 7
  • 22
1
vote
1 answer

Where to bind observables in MVVM?

I've noticed on RxSwift GitHub Login Example that observables are passed from the ViewController into the ViewModel upon its initialization : let viewModel = GithubSignupViewModel1( input: ( username:…
pflous
  • 573
  • 6
  • 17
1
vote
0 answers

RxSwift 'bindTo(aNSButton.rx_enabled)' failed

here is my code: let aDisposeBag = DisposeBag() class LoginController: NSViewController { @IBOutlet weak var accountField: NSTextField! @IBOutlet weak var passwdField: NSSecureTextField! @IBOutlet weak var loginBtn: NSButton! …
jiangjiefs
  • 149
  • 11
1
vote
1 answer

bindTo rx_text of a UITextField did not trigger the UITextField's emit event

I'm a new one to learn RxSwift. I modified the Simple Numbers example in the RxSwift Example App, which will add three numbers into a result number. I add a testStr UITextField, and an upperCase UILabel. I map testStr to uppercase and bindTo the…
Jason Yuan
  • 13
  • 3
1
vote
1 answer

ReactiveX RxSwift get first non error from concat of observables

I am using RxSwift for caching in my iOS app and have a piece of code like this: let observable = Observable.of(cache.getItem(itemID), network.getItem(itemID)).concat().take(1) observable.subscribeNext // and do some stuff I have the cache.getItem…
Josh
  • 1,688
  • 4
  • 22
  • 35
1
vote
2 answers

Is it possible to use Observable.interval in RxSwift?

Hi I have a question here, all the docs I found on RxSwift so far are using observable interval as below: let subscription = Observable.interval(0.3, scheduler: scheduler) .subscribe { event in print(event) …
air_bob
  • 1,317
  • 14
  • 26
1
vote
1 answer

Can not use proxyForObject function in DelegateProxyType (rxSwift)

I try to migrate delegate of SRWebSocket to observable. This is my RxSocketManagerDelegateProxy.swift: class RxSocketManagerDelegateProxy: DelegateProxy, DelegateProxyType{ static func currentDelegateFor(object: AnyObject) -> AnyObject?{ let…
Marina
  • 1,177
  • 4
  • 14
  • 27