Ios 与自定义信号双向绑定,但未按预期工作

Ios 与自定义信号双向绑定,但未按预期工作,ios,objective-c,reactive-cocoa,Ios,Objective C,Reactive Cocoa,我有一个自定义UITextField,它具有NSDecimalNumber值。我想将它双向绑定到我的模型的pricekeypath 问题是“价格是”字段与“价格”相对应,并且取决于我的自定义构建信号(价格、税收、折扣等信号之和) 所以我试着创建RACChannelTerminal,就像下面的代码一样,但我仍然得到无限的更新循环。TextField正在更新price,price正在更新TextField 任何人都可以给我一个提示,如何使这种双向数据绑定工作 // Connecting two wa

我有一个自定义UITextField,它具有
NSDecimalNumber
值。我想将它双向绑定到我的模型的
price
keypath

问题是“价格是”字段与“价格”相对应,并且取决于我的自定义构建信号(价格、税收、折扣等信号之和)

所以我试着创建
RACChannelTerminal
,就像下面的代码一样,但我仍然得到无限的更新循环。TextField正在更新price,price正在更新TextField

任何人都可以给我一个提示,如何使这种双向数据绑定工作

// Connecting two way PRICE
RACChannel *channelForProductPrice = [[RACChannel alloc] init];
[channelForProductPrice.followingTerminal subscribeNext:^(NSDecimalNumber *newValue) {
    self.product.price = [Price priceWithDecimalNumber:newValue];
}];
[[[[self.product rac_signalForPrice] takeUntil:[channelForProductPrice.followingTerminal
                                                ignoreValues]] map:^NSDecimalNumber *(Price *nettoPrice) {
    return [self.product calculatePriceWithTax:YES withDiscount:NO unit:YES rounded:YES].value;
}] subscribe:channelForProductPrice.followingTerminal];


RACChannel *channelForBruttoTextField = [[RACChannel alloc] init];
[channelForBruttoTextField.followingTerminal subscribeNext:^(NSDecimalNumber *value) {
    self.bruttoPriceTextField.value = value;
}];
[[[[self.bruttoPriceTextField rac_signalForValueChange] takeUntil:[channelForBruttoTextField.followingTerminal ignoreValues]] map:^id(id value) {
    NSDecimalNumber *newPrice = [value decimalNumberByDividingBy:self.product.tax.taxRatePlusOneAsPercentage];
    return newPrice;
}] subscribe:channelForBruttoTextField.followingTerminal];


[channelForProductPrice.leadingTerminal subscribe:channelForBruttoTextField.leadingTerminal];
[channelForBruttoTextField.leadingTerminal subscribe:channelForProductPrice.leadingTerminal];

它看起来像是在跟踪Terminal-(map)->price->followingTerminal,没有什么可以打破这个循环。我不认为这就是你所说的配置


您最好设置一些
RACSignal
s,而不是
RACChannel
s,使用
distinctUntilChanged
或类似工具中断周期,并根据需要使用
skip:
来停止挂接时坏值的流动。目前,我还不清楚通过它的确切信息流。

是的,我最终使用了
distinctunitrichanged
。我读到他们想从ReactiveCocoa 3.0中删除RACChannel,因为它很难检测周期。