【问题标题】:ReactiveCocoa limit the updateReactiveCocoa 限制更新
【发布时间】:2014-07-15 08:13:59
【问题描述】:

是否可以使用 ReactiveCocoa 以某种方式将更新下载时间限制为 0.3 秒? 示例:

if (the_previous_update == indefinitely)
{
update;
}
if else (current_time - the_previous_update>=0.3)
{
the_previous_update = current_time;
update;
}
else{
do nothing;
}

【问题讨论】:

    标签: xcode reactive-cocoa


    【解决方案1】:

    也许是这样的?

    RACSignal *updateSignal = ... // a signal that sends a 'next' whenever download has progressed.
    
    [[updateSignal throttle:0.3] subscribeNext:^(id x) {
      updateUI();
    }];
    

    【讨论】:

      【解决方案2】:

      是的,正如@Grav 所说,throttle 似乎是您用例的最佳操作。节流阀基本上会存储下一个事件并调度在给定时间间隔内收到的最后一个事件。

      通过限制,您可以确保每 0.3 秒更新一次 UI,并确保您用于更新的值将是在给定时间间隔内收到的最后一个值。

      这与delay 不同。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-05
        • 2011-07-28
        • 2014-06-22
        • 2012-09-16
        • 2017-04-06
        • 2016-07-06
        相关资源
        最近更新 更多