Evgeniy Kleban
Evgeniy Kleban

Reputation: 6940

RACObserver not follow property changes

I wonder why following code not work:

RACDisposable *subscr;

    subscr = [[[RACObserve(self.myTextView, text) filter:^BOOL(NSString* value) {

        return value != nil;
    }]

      // Map

      map:^id(NSString * value) {

        return [NSString stringWithFormat:@"Shock the %@", value];

    }]

     setKeyPath:@keypath(self.testLabel, text) onObject:self.testLabel];

    NSLog(@"test label text? %@", self.testLabel.text);

When i change text (type it in textField) nothing work. I know there is methods like:

 RAC(self, testString) = [self.myTextField.rac_textSignal map:^id(NSString* value) {

But my point is to test RACObserve. Code above work when i "observe" other properties.

Upvotes: 0

Views: 133

Answers (1)

Michał Ciuba
Michał Ciuba

Reputation: 7944

RACObserve uses Key-Value Observing under the hood. And most of the properties in UIKit, including UITextView.text, are not KVO-compliant.

That's why helper signals like rac_textSignal exist. Just use them if you need a signal firing each time the text changes.

Upvotes: 1

Related Questions