Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RACChannel on UITextView.text works only in one direction #939

Closed
rbeeger opened this issue Nov 13, 2013 · 8 comments
Closed

RACChannel on UITextView.text works only in one direction #939

rbeeger opened this issue Nov 13, 2013 · 8 comments

Comments

@rbeeger
Copy link

rbeeger commented Nov 13, 2013

In RACChannelTo(textView, text) = RACChannelTo(model, someTextProperty)
textView gets its text property set to someTextProperty, but editing the text in the UITextView doesn't result in someTextProperty being updated accordingly.

@Coneko
Copy link
Member

Coneko commented Nov 13, 2013

That's because UITextView does not fire KVO notifications when the text property is changed in response to the user interacting with it.
It's a common thing with UI controls. Check for the RACSupport categories on those.

The UITextView category in particular only has a signal, not a channel. Is that good enough for what you need to do?

@rbeeger
Copy link
Author

rbeeger commented Nov 14, 2013

Thanks for your answer. Even though there currently is no channel defined in the category, the question is whether one could be implemented. My knowledge of ReactiveCocoa is not thorough enough to have more than some uneducated ideas about this, but since the direction into the textview works and there is a signal for updates from the textview, shouldn't it be possible to implement the other direction and provide a complete channel?

@Coneko
Copy link
Member

Coneko commented Nov 14, 2013

Yep it should be very easy.

The reason I asked if you needed it is that you can bind to a KVO property without one:

RACChannel *modelChannel = RACChannelTo(model, someTextProperty);
RAC(textView, text) = modelChannel.followingTerminal;
[textView.rac_textSignal subscribe:modelChannel.followingTerminal];

@rbeeger
Copy link
Author

rbeeger commented Nov 14, 2013

Thanks, that works with one change. The first line is wrong as RACChannelTo returns a RACChannelTerminal. So it has to be changed to

RACChannel *modelChannel = [[RACKVOChannel alloc] initWithTarget:model keyPath:@"someTextProperty" nilValue:nil];

That works, but is ways uglier than the magic that happens with two RACChannelTos

@Coneko
Copy link
Member

Coneko commented Nov 14, 2013

Sorry my bad. RACChannelTo returns the following terminal since that's the one you want to interact with. The naming is a bit unfortunate.

RACChannelTerminal *modelTerminal = RACChannelTo(model, someTextProperty);
RAC(textView, text) = modelTerminal;
[textView.rac_textSignal subscribe:modelTerminal];

@rbeeger
Copy link
Author

rbeeger commented Nov 14, 2013

Thanks, that looks better.
Should we close this as a useable workaround exist or leave it open to get it someday into the form mentioned in the initial post.

@Coneko
Copy link
Member

Coneko commented Nov 14, 2013

I'll open a new one for that. Feel free to close this one if you don't have any follow up questions.

@fatuhoku
Copy link

For some reason this isn't really working for me. I cannot see the values that textSignal is sending out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants