rx-swift

RxSwift - Textfield-Variable binding in tableview

泄露秘密 提交于 2019-12-08 03:43:31
问题 I'm new to RxSwift and I have this code to setup a tableview which contains a textfield: budget.expenses.asObservable() .bindTo(tableView.rx.items(cellIdentifier: ExpenseInputCell.cellIdentifier, cellType: ExpenseInputCell.self)){(row, element, cell) in cell.name.text = element.name.value cell.name.rx.text .bindTo(element.name) .addDisposableTo(self.disposeBag) } .addDisposableTo(disposeBag) tableView.rx.itemDeleted .subscribe(onNext: {indexPath in self.budget.expenses.value.remove(at:

Custom UIControl subclass with RxSwift

那年仲夏 提交于 2019-12-07 11:58:59
问题 I am creating a custom subclass of UIControl (I need to override its draw method) and I want to add RxSwift to bind its isSelected property to my model. So far so good. This works fine. My problem is how can I do to change the value isSelected property in response of user touchUpInside event?. My first try was to use the addTarget method of UIControl, but changing the value of isSelected programmatically is not reported by the ControlProperty (as stated in the doc). But I can figure another

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

时光总嘲笑我的痴心妄想 提交于 2019-12-07 05:43:25
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 non NSObject protocols (I assume, if somebody can clarify that, will be a great help) My collectionView public class MyCollectionView: UICollectionView { weak var cvDelegate : MyCollectionViewProtocol? ... //rest of the code isnt related to this question in particular Now I declare delegate proxy as

How to detect if a observable has not emitted any events for specific time in RxSwift

给你一囗甜甜゛ 提交于 2019-12-06 14:36:37
问题 I am trying to detect if a observable(my case button.rx.tap ) has not emitted any value for say like 3 seconds. If yes, I would like to update the user interface. Here is my attempt so far: Observable<Int>.interval(3, scheduler: MainScheduler.instance) .takeUntil(button.rx.tap) // I know take until will stop the timer sequence .subscribe({ event in print(event) UIView.animate(withDuration: 0.4, animations: { if let number = event.element { let scale: CGFloat = number % 2 == 0 ? 1.5 : 1.0 self

Rxswift What difference between Observable.of and Observable<String>.create

折月煮酒 提交于 2019-12-06 13:13:59
I'm a newbie in rxSwift. I found some difference when create Observable by Observable.of and Observable<String>.create Observable<String>.create { observer in observer.onNext("1") observer.onNext("2") return Disposables.create() }.take(3).toArray().subscribe(onNext: { (item) in print(item) }).disposed(by: disposeBag) Not emitted util received at least 3 event. In this way observer never emitted. But with: Observable.of("1", "2") // 2 .take(3).toArray() .subscribe(onNext: { print($0) }) .disposed(by: disposeBag) But when i create by this way. Observer always emitted even if i just have 2

Re-organizing chained observables

时光毁灭记忆、已成空白 提交于 2019-12-06 12:47:12
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] location -> Observable<[JobState]?> in guard let hubs = self?.viewModel.userInfo.authorizedHubLocations

Bind two UIview fram/Position using Rxswift

▼魔方 西西 提交于 2019-12-06 05:03:06
问题 I want to change view2 position automatically when view1 position will change and bind the both view position using Rxswift. I try to observe view frame/position using this view.rx.observe(CGRect.self,"frame") .subscribe(onNext: { print($0 ?? (0,0)) }) it print frame on init time but when change view position using constraints self.constraintHorizontalCenterView.constant = 1000 it print nothing means this code not observe view position... Is there any way to observe continuously view position

Correct way to restart observable interval in RxSwift

﹥>﹥吖頭↗ 提交于 2019-12-06 05:02:11
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 immediately to reflect the changes (without having to wait for the next call). What's the best way to do this?

How to obtain a UIAlertController observable (ReactiveCocoa or RxSwift)?

房东的猫 提交于 2019-12-06 00:09:11
问题 I implemented a "reactive" UIAlertController so I can get an Observable<Int> of the button press. (See code below). My question, or questions, are: Is this implementation correct? I don't like storing the observers; I wonder if there's a better solution. Or... is there already an implementation of this in ReactiveCocoa or RxSwift? Here is the implementation. I removed the parts not relevant to te question. class AlertBuilder { typealias AlertAction = (Int) -> () private let alert:

How to bind multiple observers to one ControlProperty

♀尐吖头ヾ 提交于 2019-12-05 21:26:47
I need to bind slider.rx.value to 2 observers with different mappings. slider.rx.value.map { [unowned self] in self.formatter.string(from: NSNumber(value: $0)) ?? "" } .bindTo(textFieldAlpha.rx.text) .addDisposableTo(disposeBag) slider.rx.value.map { Enhance.Global(alpha: $0) } .bindTo(enhance) .addDisposableTo(disposeBag) But i seems that only last binding works. How to achieve this? Does this accomplish what you want? let observable = slider.rx.value.shareReplay(1) observable.map { [unowned self] in self.formatter.string(from: NSNumber(value: $0)) ?? "" } .bindTo(textFieldAlpha.rx.text)