以下の内容はhttps://anton0825.hatenablog.com/entry/20130413/1368481499より取得しました。


Reactive CocoaでViewを更新する時はthrottle:0する

Reactive CocoaでViewとViewModelをBindすると、ViewModelのプロパティを変更する度にViewの更新ロジックが実行されるのでパフォーマンスに問題が出やすい。
特にTableViewは以下のようにViewModelの配列のどこかを変更されたら都度reloadとしていると一回のRunLoopで何十回とreloadされる。

- (void)setCurrencyPairSettingViewModels:(CurrencyPairSettingViewModelCollection *)currencyPairSettingViewModels {
    _currencyPairSettingViewModels = currencyPairSettingViewModels;
    [self.currencyPairTableView reloadData];
    [self.currencyPairSettingViewModels.changeSignal subscribeNext:^(id x) {
        [self.currencyPairSettingViewModels sort];
        [self.currencyPairTableView reloadData];
    }];
}

throttleは指定秒間以下の間隔でシグナルが連続して来たらそれを無視するというメソッドなので、これを使うとRunLoop毎に一度だけViewの更新処理を実行させられる。

- (void)setCurrencyPairSettingViewModels:(CurrencyPairSettingViewModelCollection *)currencyPairSettingViewModels {
    _currencyPairSettingViewModels = currencyPairSettingViewModels;
    [self.currencyPairTableView reloadData];
    [[self.currencyPairSettingViewModels.changeSignal throttle:0] subscribeNext:^(id x) {
        [self.currencyPairSettingViewModels sort];
        [self.currencyPairTableView reloadData];
    }];
}



以上の内容はhttps://anton0825.hatenablog.com/entry/20130413/1368481499より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14