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

ReactiveCocoa vs RxSwift - pros and cons?

So now with swift, the ReactiveCocoa people have rewritten it in version 3.0 for swift Also, there's been another project spun up called RxSwift. I wonder if people could add information about what the differences in design/api/philosophy of the two…
Orion Edwards
  • 121,657
  • 64
  • 239
  • 328
72
votes
8 answers

How to use BehaviorRelay as an alternate to Variable in RxSwift?

As of RxSwift4, Variable is moved to Deprecated.swift marking the possible deprecation of Variable in future. An alternate proposed to Variable is BehaviorRelay. While posting this question, as I could not find much of the tutorial on web using…
Sandeep Bhandari
  • 19,999
  • 5
  • 45
  • 78
52
votes
4 answers

BehaviorSubject vs PublishSubject

I'm trying to get my head around the golden rule (if any) about: When to use BehaviorSubject ? and When to use PublishSubject ? The difference between them is very clear There are many kinds of subjects. For this specific requirement, a…
TooCool
  • 10,598
  • 15
  • 60
  • 85
50
votes
4 answers

RxSwift minimal Observable.create example

Currently I am trying to get RxSwift working. And I want to create a custom Observable. But I think I am doing something wrong. I have distilled what I do to this minimal sample: import Foundation import RxSwift class Example { let…
Matthijn
  • 3,126
  • 9
  • 46
  • 69
47
votes
4 answers

Swift Struct Memory Leak

We're trying to use Swift structs where we can. We are also using RxSwift which has methods which take closures. When we have a struct that creates a closure that refers to self, that creates a strong reference cycle. import Foundation import…
finneycanhelp
  • 9,018
  • 12
  • 53
  • 77
45
votes
4 answers

'[weak self]' in RXSwift closures

Do i need to use [weak self] within RXSwift subscribeNext closures? I have the code: searchController.searchBar.rx_text.throttle(0.2, scheduler: MainScheduler.instance).subscribeNext { searchText in …
Rohan Panchal
  • 1,211
  • 1
  • 11
  • 28
38
votes
3 answers

Does the order of subscribeOn and observeOn matter?

I'm a little bit confused about the order you can call the subscribeOn and observeOn methods on observables. I read a couple of posts and one guys says that it doesn't matter and just uses thing in his example and other people say it does matter. So…
user1007522
  • 7,858
  • 17
  • 69
  • 113
38
votes
2 answers

How do I create an observable of an array from an array of observables?

I have an array of Thing objects that I want to convert to ConvertedThing objects, using an asynchronous function that returns Observable. I'd like to create an Observable<[ConvertedThing]> that emits one value when all the…
Paul
  • 1,897
  • 1
  • 14
  • 28
34
votes
7 answers

RxSwift: How to add gesture to UILabel?

I have a label with isUserInteractionEnabled set to true. Now, I need to add UITapGestureRecognizer for the label. Is there a way to add in Rx way. I have looked at the RxSwift library here. Which they didn't provide any extension for adding…
Rugmangathan
  • 3,186
  • 6
  • 33
  • 44
30
votes
5 answers

Best data-binding practice in Combine + SwiftUI?

In RxSwift it's pretty easy to bind a Driver or an Observable in a View Model to some observer in a ViewController (i.e. a UILabel). I usually prefer to build a pipeline, with observables created from other observables, instead of "imperatively"…
Enrico Querci
  • 543
  • 2
  • 6
  • 11
28
votes
2 answers

use RxSwift, driver and bind to

I'm the first time to ask a question,I'm learning RxSwift, how to use bind to and driver, what's the difference between of driver and bind to.Anyone else learning RxSwift now.If you are learning RxSwift or Swift or OC,i hope we can be friends and…
GeniusFlow
  • 301
  • 1
  • 3
  • 4
27
votes
3 answers

Observing UITextField.editing with RxSwift

I want to observe the property UITextfield.editing. I'm using this code: self.money.rx_observe(Bool.self, "editing").subscribeNext { (value) in print("") }.addDisposableTo(disposeBag) But in the process of running, it's only performed once. How…
C.liu
  • 273
  • 1
  • 3
  • 5
26
votes
3 answers

RxSwift table view with multiple custom cell types

I'w wonder is there any code example for RxSwift when I can use multiple custom cells inside one table view. So for example I have two section and first section has 10 cells with type CellWithImage identifier and second section has 10 cells with…
edzio27
  • 4,126
  • 7
  • 33
  • 48
26
votes
2 answers

RxSwift - Debounce/Throttle "inverse"

Let's say I have an instant messaging app that plays a beep sound every time a message arrives. I want to debounce the beeps, but I'd like to play the beep sound for the first message arrived and not for the following ones (in a timespan of, say, 2…
Bruno Koga
  • 3,864
  • 2
  • 34
  • 45
26
votes
3 answers

How to handle "Done" return key press event in rxSwift?

While exploring RxSwift I found just textField.rx_text.asObservable() property, that fires event every keyboard button is hit. But how do we handle "search" or "done" button press events? I'd like to fire search only after these actions, not…
alex
  • 2,121
  • 1
  • 18
  • 24
1
2 3
99 100