-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Labels
Description
Here is examples of code:
_1_
RACChannelTerminal *channelTerminal = self.valueTextField.rac_newTextChannel;
RACChannelTerminal *channelTerminal2 = RACChannelTo(self.viewModel, value);
[channelTerminal subscribe:channelTerminal2];
[channelTerminal2 subscribe:channelTerminal];
[RACObserve(self.viewModel, value) subscribeNext:^(id x) {
NSLog(@"x = %@", x);
}];
_2_
RACChannelTo(self.valueTextField, text)= RACChannelTo(self.viewModel, value);
[RACObserve(self.viewModel, value) subscribeNext:^(id x) {
NSLog(@"x = %@", x);
}];
From description of RACChannelTo I supposed, that this 2 samples do the same.
But in second case logging is not working, when I start typing something in textField.
Can you clarify, what the difference between this 2 examples?
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
joshaber commentedon Aug 19, 2014
RACChannelTo
also includes askip:
: https://github.com/ReactiveCocoa/ReactiveCocoa/blob/ec8ff5fb5e76358c229f0af9699da9f462843d75/ReactiveCocoaFramework/ReactiveCocoa/RACKVOChannel.m#L187-188skywinder commentedon Aug 20, 2014
@joshaber it's my typo. But it's only about initial values. (as I understood from #1023)
It does not explain, why I don't see any logging messages, when I typing in textField in 2nd example, (but in 1-st it works.)
joshaber commentedon Aug 20, 2014
So I just noticed example 2 isn't using
rac_newTextChannel
. Is there a reason for that?skywinder commentedon Aug 21, 2014
Yes, thats it. I try to replace
RACChannelTerminal *channelTerminal = self.valueTextField.rac_newTextChannel;
toRACChannelTerminal *channelTerminal = RACChannelTo(self.uiTextField, text);
And it stop works too.
I want to observe for
self.valueTextField.text
change. Why It not works in this way?Is there some one-line alternative for "example 1" to bind my viewModel value to
UITextField
text value?Coneko commentedon Aug 21, 2014
They're not the same.
self.valueTextField.rac_newTextChannel
sends values when you type in the text field, but not when you change the text in the text field from code.RACChannelTo(self.uiTextField, text)
sends values when you change the text in the text field from code, but not when you type in the text field.skywinder commentedon Aug 21, 2014
@Coneko got it, thanks!
So, if I want to observe changes from user's typing in
UITextField
- there is no shorter way than 4 lines to bind the value and textField?Coneko commentedon Aug 21, 2014
Yep.
shyboy2012 commentedon Nov 27, 2017
try RACChannelTo(self.viewModel, value) = self.valueTextField.rac_newTextChannel;