rx-swift

Rx Swift : Complex TextFields Validation

我的未来我决定 提交于 2019-12-14 01:14:05
问题 I'm new to RxSwift and all example I found are handling simple cases. I'm trying to do form validation for my textfields. My custom TextField class has a method isValid() and a regexp . The isValid return is based on the regexp attribute. So far, I have written the following : let valids = [mLastName, mFirstName, mEmailField].map { $0.rx.text.map { text -> Bool in // I want more complex logic here // Like return field.isValid() return text!.characters.count > 0 } } let _ = Observable

RXSwift: Modifying URLRequest if request fails in `retryWhen`

强颜欢笑 提交于 2019-12-13 03:37:20
问题 I need to modify the headers of the request when the request fails but the request doesn't change when I modify the request in retryWhen Here is my implementation: func makeRequest(serviceRequest: URLRequest) { let maxRetry = 2 var localRequest = serviceRequest request(request: localRequest).retryWhen { errors in return errors.enumerated().flatMap { (arg) -> Observable<Int64> in localRequest.setValue("someValue", forHTTPHeaderField: "someKey") let (index, error) = arg return index <= maxRetry

How to realize UIPickerView with RXSwift

拥有回忆 提交于 2019-12-12 11:46:45
问题 just like UITableView items.bindTo(tableView.rx.items(cellIdentifier: "cellIdentifier", cellType: AttentionTableViewCell.self)){(row,dic,cell) in cell.configueCell(with: dic) }.addDisposableTo(dispose) 回答1: Maybe you just have to update your RxSwift library version. It looks like pretty much the same as UI{Table|Collection}View rx bindings. Supposing you have a data source like: let items: Observable<[String]> = Observable.of(["Row1", "Row2", "Row3"]) To populate your UIPickerView: items.bind

How to unsubscribe from Observable in RxSwift?

守給你的承諾、 提交于 2019-12-12 10:33:51
问题 I want to unsubscribe from Observable in RxSwift. In order to do this I used to set Disposable to nil. But it seems to me that after updating to RxSwift 3.0.0-beta.2 this trick does not work and I can not unsubscribe from Observable: //This is what I used to do when I wanted to unsubscribe var cancellableDisposeBag: DisposeBag? func setDisposable(){ cancellableDisposeBag = DisposeBag() } func cancelDisposable(){ cancellableDisposeBag = nil } So may be somebody can help me how to unsubscribe

RxBluetoothKit Code Pattern for Multiple Stage Bluetooth Commands

旧城冷巷雨未停 提交于 2019-12-12 04:14:22
问题 I've started using RxBluetoothKit with good results for a peripheral we are developing. It works quite well and I am able to perform the transactions we need. I have a design pattern question. We have a couple of commands where our API includes multi-step commands. For example, the App writes a command start code, the Peripheral confirms with an ACK, then the App writes the command, waits for an ACK, issues another command, waits for another ACK, etc. This can go on until the App issues a

Casting Moya Response error to defined type

☆樱花仙子☆ 提交于 2019-12-11 19:28:17
问题 I am using RxMoya for my networking calls and extending PremitiveSequence and Response so as to handle the error coming back. I declared a struct of Networking error which I could use to get all the error details and as such Pass the error message via the BaseResponse Model. Here is my NetwokingError struct public struct NetworkingError: Error { let httpResponse: HTTPURLResponse? let networkData: Data? let baseError: Error } For my coding, I have extended the primitive sequence as follows

Generic way to call Network Requests for API Client

时间秒杀一切 提交于 2019-12-11 17:51:45
问题 I have provided the code for my firebase API client. Is it smart to use generics, to initialize any entity straight from json this way? To download lists, I needed an indicator to let me know that I'm requesting a list of entities- since there's different implementation, so I added a GETALL case to my HTTPMethod enum, is this bad, and something that would be confusing to others? I also feel like this isn't flexible because I can't get desired entities on a node if there are nested at

Rx scan(), cannot generate observable from seed and another observable

大兔子大兔子 提交于 2019-12-11 14:14:32
问题 I have a seed value Triangle (Bool) and an observable that emits values Circle (Int) . My intention is to generate a new observable (Triangle, Circle) each time a value is emitted from that observable, transforming the Triangle value negating the current value. This is my marble diagram: But I cannot achieve it, and I don't know if scan is the correct operator. This is my code: typealias Triangle = Bool typealias Circle = Int func scan() { let triangle: Triangle = false circleObservable .scan

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

喜欢而已 提交于 2019-12-11 08:14:47
问题 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 Variable<..> in the ViewModel changed! Ask the ViewModel for the data you need to update the UI and update the UI!" And then the ViewController call a method updateUI() inside the

Xcode 9 crashes when debugging in swift [closed]

末鹿安然 提交于 2019-12-11 07:27:43
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I'm using the latest RxSwift library for reactive programming and facing a strange problem when debugging my code in Xcode 9.1! I have a collectionView inside tableView header and bind selectedItem of collectionView to ViewModel variable to filter out section items. But when I change selected item of