Questions tagged [rx-swift]

1

votes
1

answer
281

Views

IOS Rxswift use Kingfisher to prefetch cell Image

I'm trying to implement Kingfisher prefetch feature inside an Rxswift project. The problem is with these 2 function collectionView.rx.prefetchItems collectionView.rx.cancelPrefetchingForItems The instruction at Kingfisher github is quite short override func viewDidLoad() { super.viewDidLoad() colle...
Lê Khánh Vinh
1

votes
3

answer
1k

Views

Rxswift change value of observed object

I am fairly new to Rx and to Reactive Programming in general. I am simply trying to make things work. I'm trying to populate an object after a request to an API (Github's API for the matter): The object to populate : class GithubUser { var login: String? var joinDate: Date? var email: String? } The...
Thiryn
1

votes
1

answer
502

Views

How to reset the Observable interval operator in RXSwift?

I'm new in RXSwift and i defined an Observable interval timer sequence that calls a webservice method every second. In that webservice response, i receive new retry time value that must replace with my current time. How to reset this sequence with new time value? This is my code : func mySequence()...
iSibDev
1

votes
2

answer
377

Views

How edit/delete UICollectionView cells using MVVM and RxSwift

I am trying to understand how to implement MVVM with a list of objects and an UICollectionView. I am not understanding how to implement the User iteration -> Model flow. I have setup a test application, the Model is just a class with an Int, and the View is an UICollectionViewCell which shows a text...
Rui Rodrigues
1

votes
1

answer
611

Views

RXSwift, a Struct as a Variable

So basically I have a struct struct MyStruct { var foo : String = '' var bar : String = '' } Now I want to do the following : Observe change in an RxVariable of MyStruct, so that whenever that variable is changed, we also have an observer to that variable, we will be able to get the new struct in...
Saheb Roy
1

votes
1

answer
122

Views

RxSwift - order of emit on PublishSubject

I know, that all types of Rx subjects can get elements in subscribe not ordered correctly, eg. if I send three elements in order 1,2,3, there is an option to get it on this order: 1,3,2. I wonder, is there a way to force the order of emitted elements the same at the start and at the end?
MiXen
1

votes
0

answer
271

Views

RxJava Scan emits first item, other RX libraries do not. Why?

The scan() operator that takes a seed in RxJava emits the seed upon every subscription. Other RX languages, like RxJS & RxSwift do not do this. Seed value is never emitted. Why is this? Is it safe to assume RxJava has an added feature where other RX languages never expected a scan to act like that....
LEO
1

votes
0

answer
424

Views

Is this the best way to convert Swift protocol to RxDelegateProxy?

Sorry I could not come up with better title than that, Ill modify it if anybody suggests a better one after. I have a protocol @objc public protocol MyCollectionViewProtocol { func scrollViewShouldScrollToTop() } I have declared it to be @objc because unfortunately DelegateProxy does not work with...
Sandeep Bhandari
1

votes
0

answer
412

Views

How put a custom view on a selected row for an uipickerview rxswift?

I use Pickerview with Rx and i would like to know how you can change view of the selected row with a custom view. i tried on a picker view without RX it works. But the same with Rx and Custom Adapter don't work. Do you have an idea to do this ? Thanks for your answers : For example without Rxswift :...
julien hamon
1

votes
0

answer
386

Views

awakefromnib not called for UICollectionReusableView when using RxSwift datasource

I'm using RxSwift, I managed to create the dataSource and I retrieve cells correctly. Problem is with the section headerView. I have created a UICollectionReusableView class, attaching outlets from storyboard. The problem is that I retrieve the view with collectionview.dequeueReusableSupplementaryV...
Andrea.Ferrando
1

votes
1

answer
971

Views

Ignore error on Completable - RxSwift

Is there a way to ignore a completable if there is an error ? For example, I wan't to remove value in my Firebase Realtime Database, and delete a picture to Firebase Storage when the first completable has finish : // MARK: DELETE - FUNCTION public func delete(id: String) -> Completable { return data...
fredericdnd
1

votes
1

answer
163

Views

Tail recursion when loading lot of items

I need to load a lot of small files from an api that allows me to load only one file at a time. As they are very small I start several downloads at a time. Depending on the result I start the next batch load. For each request I use a observable and then combine several with combineLatest. After comb...
beseder
0

votes
0

answer
12

Views

Binding BehaviorRelay with Observable - RxSwift

I have such code as below. How can I achieve it in one chain, without using subscribe on timer? I would like to attach 'timerInterval' to 'timer' and then call subscribe. var timerInterval: BehaviorRelay = BehaviorRelay(value: '') ... func doLogic() { let timer = Observable.interval(0.05, scheduler:...
Marin
1

votes
1

answer
462

Views

Make RxCocoa binding for UIPageViewController.setViewControllers (how to synchronize Observable)

currently, I want to bind the value of Observable to my UIPageViewController. Initial idea is simple and straightforward: viewControllerObservable .subscribe(onNext: { [weak self] viewController in self?.pageVC.setViewControllers([viewController], direction: .forward, animated: false, completion:...
cleg
1

votes
1

answer
528

Views

Chaining operations with RxSwift

I want to chain following operations createUserandVerify Create Anonymous User (user) Verify User -> verifiedUser If verification successful return verifiedUser else return user Get stuff with coredata getStuff If stuff.count > 0 Upload stuff with user credentials uploadStuff Finally report the res...
Meanteacher
1

votes
1

answer
404

Views

RxSwift, ViewModels and UI-bindings

I'm wondering what best practice is in the following situation: Project setup is Model-View-ViewModel I need to display a screen with text fields (e.g. name) where the user an edit details of a specific Model ViewModel contains an Observable; ViewModel is responsible for retrieving data from the API...
Rutger Bresjer
1

votes
0

answer
98

Views

How to handle unique cell action with mvvm

I have unique cell in UITableView, which has two buttons. I need to bind these actions to viewModel of controller. I bind view with view model in this way: func attach(wrapper: Attachable) -> ViewModel { self.viewModel = wrapper loadViewIfNeeded() let viewModel = self.viewModel.bind(bindings: bindin...
dprox
1

votes
0

answer
109

Views

Using “ViewState” in RxSwift/MVVM

This question is very broad but I'm not sure which aspect of it I should focus on. I have a goal to abstract away the recurring patterns of my screens such as errors, loading, empty data. The views that represent these states will not change much between the many screens I have. Perhaps they coul...
Alex Bollbach
1

votes
1

answer
226

Views

Avoid Nested RxSwift Subscriptions

I have to work with 2 database objects which are related to each other. The way I have done it created nested subscriptions. I read a couple of blogs but couldn't find a way to do away with nested subscriptions. Any pointers would be appreciated. A topic has a list of children. After retrieving all...
Astha Gupta
1

votes
1

answer
380

Views

RxSwift bind to with animation with RxCocoa

I have a UIStepper value binded to a UILabel text: unitsStepper.rx.value.asObservable() .map { Int($0).description } .bind(to: stepperCountLabel.rx.text) .disposed(by: rx.disposeBag) And i would like to animate the label every time it changes, theres a better way to that instead of this? unitsStepp...
Godfather
1

votes
0

answer
112

Views

Make a queue of events RxSwift

I would like to know if it is possible make a queue (with identifier for example, like 'Q') with RxSwift like: On ViewController1 I send an event1 to queue Q. On ViewController2 I send other event2 to Q. On ViewController3 I handle the events 1 and 2 of the queue, with identifier Q. EDIT, specifi...
Eironeia
1

votes
1

answer
152

Views

CollectionView in tableViewCell MVVM

I am building an app in Swift 4 using MVVM non reactive. I would like to call viewmodel updates from the tableView's View model in order not to turn it into spagetthi code. Instead of creating one view model for each collectionViewCell I am trying to update from main ViewModel. //Spaghetti option (V...
Neil
1

votes
2

answer
109

Views

Map a list of one type to another in RxSwift but keep existing ones

I've been running into this every now and then I'm always questioning myself whether I'm using RxSwift (or reactive means altogether) the wrong way. The challenge is converting value types to something representable on the UI. Usually on the lower level I'm storing data with simple types but I need...
mkko
1

votes
1

answer
74

Views

RxSwift - call sequence of a function after Mapping

I'm trying to call a function after a successful completion of a mapping. The observable is created from an existing stream by mapping. Inside the mapping block, I subscribe to get the output which is mapped to the final type. With the updated stream, I'm looking at calling the function. But the fun...
1

votes
1

answer
103

Views

RxSwift MVVM implemention inquire

I have two UITextField and one UITableView in one UIViewController. The ViewModel of this UIViewController exposes one Observable to be the table view datasouce. The two UITextField take the parameters from users and refresh the table view Observable. UITextField are using UIPickerView as InputView...
benoitcn
1

votes
2

answer
784

Views

Cannot convert return expression of type 'PrimitiveSequence<SingleTrait, String>' to return type 'Observable<String>'

I am getting error Cannot convert return expression of type 'PrimitiveSequence' to return type 'Observable' a Single returns PrimitiveSequence, so how can I convert it to Observable of type String? return Single.create(subscribe: { (single) in single(.success('test')) return Disposables...
Sam Shaikh
1

votes
1

answer
394

Views

Generic parameter 'Element' could not be inferred?

'Generic parameter 'Element' could not be inferred' - this error comes as I write guard statement - what is inside guard statement which causes error that element could not be inferred. static func makeTokenForCard(with cardinfo: CardInfo) -> Single { return Single.create { single in guard let ck =...
Sam Shaikh
1

votes
1

answer
53

Views

iOS RxSwift does connectable observable from .replay() pass completion events to subscribers?

I’m trying to get some more clarity around connectable Observables. Does connectable observable pass onComplete events to subscribers at the end of replay, if source has terminated? I have seen answer suggesting that it should, but it does not seem to do so in RxSwift. Is this my bug, or is this...
Alex Stone
1

votes
1

answer
148

Views

iOS MVVM handling initial view state

I am trying to use MVVM without Rx in Objective C, basically something like MVP. I have some very basic doubts that I would like to clear 1.) How to load the initial view state in view, based on configuration. i.e. when the initial state of UI components can change based on some configuration values...
tarun_sharma
1

votes
1

answer
203

Views

RxDataSources not updating section header title

I'm using RxDataSources to load and display a UITableview. I am trying to update the section header with the amount of items that it holds, however tough the cell and items update correctly, the title remains stale. This is my code for the DataSource object: tableViewDataSource = RxTableViewSectione...
Yoav Schwartz
1

votes
1

answer
224

Views

RXSwift + Moya + Error Handling + Refresh Button

I am trying to set up a tableview that refreshes user data after a button is pressed. RXSwift is used for the entire chain of events. Moya is used for routing. I am trying to use the standard error handling given by Moya, which is: provider.rx.request(.userProfile('ashfurrow')).subscribe { event in...
Rowan Gontier
1

votes
2

answer
121

Views

can't return observable of customError in network call

I want to use catchError for getting back my error as custom type. At first, I want my network layer return Observable and then in ViewModel I subscribed it for .OnNext, .OnError, .OnCompleted events, But I don't know how should I handle Errors such as 4xx, 5xx network status code and then, them ret...
Mahdi
1

votes
1

answer
82

Views

Contextual closure type '(_, _) -> _' expects 2 arguments error when using RxSwift Observable.zip

How to fix following build error when building the code below: Contextual closure type '(_, _) -> _' expects 2 arguments, but 1 was used in closure body Insert ', ' Code func getIncidentAndResolutionTree() -> Observable { return Observable.zip(getIncidents(), getResolutionTree(), resultSelector: { r...
Adobels
1

votes
1

answer
41

Views

Swift type checker rejects protocol that has a class requirement as a class type

This is about an error encountered in https://github.com/RxSwiftCommunity/RxStarscream/pull/23. I am trying to generalize a type, so I can mock the class it is based on. This means I want to switch from a concrete implementation to a protocol. The original class looks like this: open class WebSocket...
Felix Bohm
1

votes
0

answer
101

Views

how to properly install “RxSwift” module?

I'm trying to build a project that uses RxSwift module, XCode keeps complaining with the error 'no such module RxSwift'... I've tried to install this module several times, in the terminal I got the following message after pod install Analyzing dependencies Downloading dependencies Using RxCocoa (4....
Lucas
1

votes
3

answer
216

Views

How to make ViewController observe any changes to ViewModel variables (Variable<..>) with RxSwift?

How can I observe changes to Variable value (RxSwift Variable) inside the ViewModel class from the ViewController? So in case the value of any of my Variable that I have in the ViewModel changes within the things happening in the ViewModel then the ViewController will be noticed 'Hey! One or more Va...
denis_lor
1

votes
0

answer
21

Views

Crashlytics Swift wrong error “path” on Firebase dashboard

I created an extension of Observable, Single and Completable to report a non-fatal issues to Crashlytics when an error occurs in the do(onError:) RxSwift method. It works like that : myObservable.handleError(). This method is functional, but the report in Firebase dashboard doesn't show the real sou...
fredericdnd
2

votes
1

answer
17

Views

RxSwift multiple observable in map

I ran into a situation where I would fetch an API which will generate json data of registered users. I would then have to loop through each user and fetch their avatar from remote url and save it to disk. I can perform this second task inside subscribe but this is not a best practice. I am trying to...
codelearner
1

votes
0

answer
49

Views

How to perform search using RxRealmDataSources?

I have stored data on realm and show it in a UITableView using RxRealmDataSources as follows - let items = Model.getChangesetObservable() let dataSource = RxTableViewRealmDataSource(cellIdentifier: 'ItemTableViewCell', cellType: ItemTableViewCell.self) { cell, ip, item in cell.titleLabel.text = ite...
iaaflaafc
1

votes
2

answer
167

Views

RxSwift: How to create cache for last network response without creating class/struct property?

I'm working on iOS App that uses the IP Stack API for geolocation. I'd like to optimise the IP Stack Api usage by asking for external (public) IP address first and then re-use lat response for that IP if it hasn't changed. So what I'm after is that I ask every time the https://www.ipify.org about ex...
bdolewski

View additional questions