gpt4 book ai didi

ios - RxSwift 中 RACCommand 的等价物是什么?

转载 作者:可可西里 更新时间:2023-11-01 00:59:54 31 4
gpt4 key购买 nike

我有一个 View 和一个 View 模型。 View 包含一个按钮,每次用户按下它时,我都希望 View Model 得到通知。我还希望在第一个 View 模型收到事件时通知第二个 View 模型。

因此点击事件将按如下方式传播:

Button -> ViewModel1 -> ViewModel2

我可以通过将 button.rx_tap 绑定(bind)到 viewModel1.onButtonTapped() 来设计它,但是因为我希望 viewModel2 订阅也得到事件,我需要某种可观察到的接收 Action 并传播它的对象。我相信这就是 RACCommand 所做的。

我如何使用 RxSwift 实现它?

最佳答案

现在在 RxSwift 本身中没有直接等同于 RACCommand

但是,在RxSwiftCommunity 中有一个项目,叫做Action ,其灵感来自 RACCommand

RxSwift 的创建者在 GitHub issue建议在 RACCommand 可能有用的某些情况下可以使用 ActivityIndi​​cator 类。

关于ios - RxSwift 中 RACCommand 的等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36070549/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com