ReactiveCocoa:仅订阅新值

时间:2022-05-08 08:08:14

I've created an event subscriber in viewDidLoad, as follows:

我在viewDidLoad中创建了一个事件订阅者,如下所示:

[RACObserve(_authenticationView.passwordInput.textField, text) subscribeNext:^(NSString* text)
{
     //handle this
}];

This fires whenever the textField.text property changes (expected), however it also fires once when created, or for the intitial value, which is not what I want.

每当textField.text属性发生更改(预期)时都会触发,但是它在创建时也会触发一次,或者触发初始值,这不是我想要的。

Of course I could filter this out, but I only want to filter the first event out. How do I do this?

当然我可以过滤掉它,但我只想过滤掉第一个事件。我该怎么做呢?

Requirements:

要求:

  • If the password has a new empty value, present a validation message (can't proceed password empty).
  • 如果密码具有新的空值,则显示验证消息(无法将密码设置为空)。
  • If the password has a new non-empty value, talk to remote client.
  • 如果密码具有新的非空值,请与远程客户端通信。

. . so what's the cleanest way to do this?

。 。那么最干净的方法是什么?

1 个解决方案

#1


21  

If you just want to skip the first value, just stick a -skip:1 in there:

如果您只想跳过第一个值,只需在其中粘贴-skip:1:

[[RACObserve(_authenticationView.passwordInput.textField, text) skip:1] subscribeNext:^(NSString* text)
{
     //handle this
}];

#1


21  

If you just want to skip the first value, just stick a -skip:1 in there:

如果您只想跳过第一个值,只需在其中粘贴-skip:1:

[[RACObserve(_authenticationView.passwordInput.textField, text) skip:1] subscribeNext:^(NSString* text)
{
     //handle this
}];