ReactiveCocoa / ReactiveCocoa

Cocoa framework and Obj-C dynamism bindings for ReactiveSwift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RACChannel on UITextView.text works only in one direction

rbeeger opened this issue · comments

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.

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?

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?

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];

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

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];

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.

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

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