rx-cocoa

Get model from UICollectionView indexpath

余生颓废 提交于 2020-08-08 05:34:06
问题 I'm using RxSwift to bind a model array to a collection view How do I get the model object from a given indexPath? I'm doing the binding like this: vm.bikeIssueCatagories() .drive(self.collectionView.rx.items(cellIdentifier: "BikeIssueCategoryCollectionViewCell", cellType: UICollectionViewCell.self)) { row, data, cell in }.disposed(by: disposeBag) The core of my issue is, that I need to get both the model object and the cell that a user selects. Using collectionView.rx.modelSelected(T.self)

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

RxSwift/RxCocoa: prevent UITextField from having more than … characters

别说谁变了你拦得住时间么 提交于 2019-12-18 19:42:28
问题 I would like to have a UITextField configured with RxSwift/RxCocoa so that it only contains up to ... characters. I do not want to use the UITextFieldDelegate for this but would love to achieve this with RxSwift/RxCocoa. Is there a way to do this? 回答1: Sure: textField.rx.controlEvent(.editingChanged).subscribe(onNext: { [unowned self] in if let text = self.textField.text { self.textField.text = String(text.prefix(40)) } }).disposed(by: disposeBag) In this example, the textfield is limited to

Subscribe to UINavigationController back button with RxSwift / RxCocoa

你说的曾经没有我的故事 提交于 2019-12-11 04:26:54
问题 I have a simple test project with a UINavigationController as my rootViewController . I push the first ViewController which has a + button as right bar button item, I subscribe to its taps to present a new ViewController (which is identical to the previous one). The push segue works as I expect. UIKit manages the back button for me and I think it is UINavigationController that makes the magic behind the scene. Now, what I need to do is subscribe to the back button, but I can't find how to do

RxTest: Undefined symbols for architecture x86_64 and arm64

ぐ巨炮叔叔 提交于 2019-12-11 02:45:40
问题 I am trying to run the following test from Chapter 16: Testing with RxTest of Raywenderlich RxSwift book: import XCTest import RxSwift import RxTest @testable import Testing class TestingViewModel : XCTestCase { var viewModel: ViewModel! var scheduler: ConcurrentDispatchQueueScheduler! override func setUp() { super.setUp() viewModel = ViewModel() scheduler = ConcurrentDispatchQueueScheduler(qos: .default) } func testColorNameIsRayWenderlichGreenWhenHexStringIs006636() { // 1 let

RxSwift + UITableViewCell how to get cell object in heightForRowAt

蓝咒 提交于 2019-12-10 09:28:40
问题 I have a view controller with UITableView. The table data is populated using RxSwift: let observable = Observable.just(data) observable.bindTo(tableView.rx.items(cellIdentifier: "CategoryCell", cellType: CategoryCell.self)) { (row, element, cell) in cell.setCategory(category: element) }.disposed(by: disposeBag) tableView.rx.setDelegate(self).disposed(by: disposeBag) and I have the following delegate function: func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) ->

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:

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

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

Reload Tableview using RxSwift

試著忘記壹切 提交于 2019-12-05 02:34:42
问题 I am using RxSwift for tableview. I need to reload my table each time after getting data from api but I'm failed to do this. I couldn't find any solution for that. Can anybody help? I have an array of places obtain from response of an Api.I have used this code in view did load, but its is not being called when array is updated. 回答1: I have found the issue. My array was not being getting updated correctly. I did the following changes. Declare dataSource variable of ModelClass: let dataSource =