OGeek|极客世界-中国程序员成长平台

标题: ios - RACDelegateProxy 与 Common Delegate 实现 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:16
标题: ios - RACDelegateProxy 与 Common Delegate 实现

我正在研究 ReactiveCocoa(我不擅长 FRP,也不擅长纯函数式编程),并且我看到了 RacDelegateProxy 类,它可以抽象具有 void 返回值的委托(delegate)方法的实现。我不太明白的是使用它有什么好处,当我们与传统的实现进行比较时,即实现每个方法并获得调用。那么,使用 RACDelegateProxy 而不是以传统方式实现的主要区别和好处是什么?

代码示例(使用 ReactiveCocoa):

self.deselectDelegate = [[RACDelegateProxy alloc] initWithProtocolprotocol(UITableViewDelegate)];
[[self.deselectDelegate rac_signalForSelectorselector(tableView:didDeselectRowAtIndexPath]
 subscribeNext:^(RACTuple *arguments) {
     // code ...
 }];

VS(传统实现):

- (void)tableViewUITableView *)tableView didDeselectRowAtIndexPathNSIndexPath *)indexPath {
    // code ...
}



Best Answer-推荐答案


您的问题可以概括为“信号相对于回调的优势是什么”。

以前在 RAC's github repo 上有一个链接称为 Escape from Callback Hell - 链接不再有效,但我认为该标题完美地突出了这一点。

基本上,FRP 的优点之一是将所有异步模式(KVO、委托(delegate)、通知等)转换为信号,这会导致:


编辑

发现提到的文章已存档:Escape from Callback Hell

关于ios - RACDelegateProxy 与 Common Delegate 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30193633/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4