rx-swift

Observing UITextField.editing with RxSwift

主宰稳场 提交于 2019-12-31 18:58:31
问题 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 do I solve this,please 回答1: Don't observe the editing property, because it's not just a stored property. It's defined as: public var editing: Bool { get } So you don't know how UIKit is actually getting that value. Instead, use rx.controlEvent and

Swift Struct Memory Leak

≯℡__Kan透↙ 提交于 2019-12-31 08:13:27
问题 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 RxSwift struct DoesItLeak { var someState: String = "initial value" var someVariable: Variable<String> = Variable("some stuff") let bag = DisposeBag() mutating func someFoo() { someVariable.subscribeNext { person in self.someState = "something" }

How to use RxDataSource with SearchBar?

▼魔方 西西 提交于 2019-12-31 04:07:09
问题 I master RxSwift and when using RxDataSource, the SearchBar delegates do not work for me and he, I can’t see the error. Without RxDataSource everything works, on other screens I have no problems. Tell me, with a fresh look, what is the mistake? why doesn't the filter happen? private var defaultCategories: [Groups]! var groupsCoreData = BehaviorRelay<[Groups]>(value: []) override func viewDidLoad() { super.viewDidLoad() searchBarRx() tableViewRx() } let dataSource =

RXSwift User input on error and continuation

给你一囗甜甜゛ 提交于 2019-12-24 11:47:20
问题 I'm quite new to RX and I'm trying to understand how I can continue a task, after an error which requires user input. A concrete example would be two factor authentication.. We have an auth-service and a protected resource. Logging in, we receive from the auth-service a LOA-2 (username&password used) token. trying to fetch data from the protected resource we receive an error stating we need LOA-3 (two-factor). So we have to get the input from the user, send it to the auth-service, get a new

RxSwift : manage object updates in the app

筅森魡賤 提交于 2019-12-24 10:59:36
问题 I have a big concern about how to manage object properties changes. Imagine I have a "car" class, with some properties like "name", "date", "price" etc. In my view "A", I'm displaying all cars I retrieve from a API. In a view B & C, I can display and edit specific information about the car selected in the view A (let's say it's "car AAA"). it's possible too, to refresh the car object with a API call to retrieve the last information about the car. I want to be able to update the view A, if the

RxSwift, RxCocoa and UITableview

半世苍凉 提交于 2019-12-24 07:50:41
问题 I have a problem with implementing a UITableView using RxSwift. I tried to bind an observable of an array of models to the table items with the following code. models.bind(to: self.tableView.rx.items(cellIdentifier: "Cell", cellType: ModelTableViewCell.self . But when I do it gives me the following error: Type 'inout UITableView' does not conform to protocol 'ReactiveCompatible' and I know the error can't be right because NSObject extends ReactiveCompatible so UITableView also does. Also, my

Can not use proxyForObject function in DelegateProxyType (rxSwift)

独自空忆成欢 提交于 2019-12-24 07:26:05
问题 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 socket: SRWebSocket = object as! SRWebSocket return socket.delegate } static func setCurrentDelegate(delegate: AnyObject?, toObject object: AnyObject) { let socket: SRWebSocket = object as! SRWebSocket socket.delegate = delegate as? SRWebSocketDelegate }

iOS RxSwift how to prevent sequence from being disposed on (throw error)?

我的未来我决定 提交于 2019-12-23 21:17:33
问题 I have a sequence made up of multiple operators. There are total of 7 places where errors can be generated during this sequence processing. I'm running into an issue where the sequence does not behave as I expected and I'm looking for an elegant solution around the problem: let inputRelay = PublishRelay<Int>() let outputRelay = PublishRelay<Result<Int>>() inputRelay .map{ /*may throw multiple errors*/} .flatmap{ /*may throw error*/ } .map{} .filter{} .map{ _ -> Result<Int> in ...} .catchError

Re-organizing chained observables

[亡魂溺海] 提交于 2019-12-22 18:58:29
问题 I have a pretty hefty chunk of chained Rx observables that are fired when a tableviews row is selected via table.rx.modelSelected . I'd like to be able to break this logic up, because I'm currently having to execute business logic in flatMapLatest , because it's "Step 1" to the process (which feels wrong), and I have to execute more business logic in the subsequent subscribe ("Step 2"). Here's the code I'm using: locationsTable.rx.modelSelected(Location.self) .flatMapLatest { [weak self]

Correct way to restart observable interval in RxSwift

和自甴很熟 提交于 2019-12-22 12:33:32
问题 In my OS X status bar app I'm using interval function to periodically call an external api and display the result: Observable<Int> .interval(120.0, scheduler: MainScheduler.instance) .startWith(-1) // to start immediately .flatMapLatest(makeRequest) // makeRequest is (dummy: Int) -> Observable<SummaryResponse?> .subscribeNext(setSummary) .addDisposableTo(disposeBag) However, if user changes the preferences in the meantime, I would like to "restart" this interval and make a new call