rx-swift

How to bind multiple observers to one ControlProperty

浪子不回头ぞ 提交于 2019-12-10 10:18:08
问题 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? 回答1: Does this accomplish what you want? let observable = slider.rx.value.shareReplay(1) observable.map {

How do I implement a Swift protocol with a generic constrained type property?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 09:45:16
问题 I would like to have a protocol that looks something like this: protocol ReturnType { var returnType: ImmutableMappable.Type { get } } The part of the enum implementing the protocol: extension ShimEndPoint: ReturnType { var returnType: ImmutableMappable.Type { switch self { case .deAuthorize(_, _): return EmptyResponse.self case .authorize(_, _): return AuthorizeResponse.self case .step(_, _, _, _): return StepResponse.self } } } EmptyResponse, AuthorizeResponse and StepResponse all implement

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) ->

When should we call addDisposableTo(disposeBag) in RxSwift?

﹥>﹥吖頭↗ 提交于 2019-12-10 01:33:52
问题 We create a DisposeBag , and a Observable , subscribe the Observable and then addDisposableTo(disposeBag) , I know when the DisposeBag is going to deinit, it will call dispose() to release resources otherwise it will lead memory leak. If the Observable send Complete or Error that terminate in finite time. When the Observable terminate before DisposeBag deinit, do I have the need to call addDisposableTo(disposeBag) ? Does DisposeBag automatically release the observer that subscribed to it when

How to convert Delegate to Observable RxSwift?

…衆ロ難τιáo~ 提交于 2019-12-09 07:38:18
问题 I have delegate methods, which I need to wrap by Delegate Proxy in RxSwift. I have done it using Bond and Reactive, but here, in RxSwift, I am not able to find the proper way to convert it. Follow is Protocols import UIKit /** A protocol for the delegate of a `DetailInputTextField`. */ @objc public protocol CardInfoTextFieldDelegate { /** Called whenever valid information was entered into `textField`. - parameter textField: The text field whose information was updated and is valid. -

RxSwift - UILabel field not being updated when UITextField updated programmatically

与世无争的帅哥 提交于 2019-12-08 17:32:08
问题 I'm just learning RxSwift and have a simple example that I'm not sure why it is not working. I have a text field and a label field. ANY time the text field changes, I'd like the label field to be updated. If I type in the text field, everything works as expected. If I set the text field programmatically, such as when I push a button and set the text field explicitly, the label field is not updated. import UIKit import RxSwift import RxCocoa class ViewController: UIViewController { @IBOutlet

RxDataSources tableView with multiple sections from one API source

旧街凉风 提交于 2019-12-08 12:52:54
问题 Currently for our API requests we use Rx. An example of how we use it is: let orderRxService = OrderRxService.listAsShop(shopId, status: .active) .repeatRequest(delay: 4) .observeOn(MainScheduler.instance) .subscribe( onNext: { [weak self] orders in self?.orders = orders self?.tableView.reloadData() }) .disposed(by: disposeBag) This gets all orders for given shopId with the status .active . On every update the local orders object is replaced and the tableView is reloaded. This reload the

IOS Rxswift use Kingfisher to prefetch cell Image

五迷三道 提交于 2019-12-08 07:37:53
问题 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() collectionView?.prefetchDataSource = self } extension ViewController: UICollectionViewDataSourcePrefetching { func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths:

IOS Rxswift use Kingfisher to prefetch cell Image

99封情书 提交于 2019-12-08 07:26:33
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() collectionView?.prefetchDataSource = self } extension ViewController: UICollectionViewDataSourcePrefetching { func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) { let urls = indexPaths.flatMap { URL(string: $0.urlString) } ImagePrefetcher(urls: urls).start() }

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

て烟熏妆下的殇ゞ 提交于 2019-12-08 05:39:29
问题 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 :