RACObserve (), RAC () - how to set BOOL value based on NSString

Being a newbie to ReactiveCocoa, I hope for some tips:

I am trying to create a dynamic form containing several Field objects processed by an XML file. Each field can have several validation rules that will be executed with the Field parameter NSString *value.

For the RAC part of the question

inside each Field object, I want to bind BOOL completedto a signal that checks the Field parameter *valuefor an array of rules. So far, I got my opinion here:

@implementation Field

self = [super init];
if (self) {

    RAC(self, completed) = [RACObserve(self, value) filter:^BOOL(NSString *fieldValue) {
        NSLog(@"%s::self.completed = %d\n", sel_getName(_cmd), self.completed);  // trying to watch the values here, with no luck 
        NSLog(@"%s::fieldValue = %@\n", sel_getName(_cmd), fieldValue);  // same here, I'd like to be able to view the `*value` here but so far no luck

        return [self validateCurrentValue]; // currently this method just checks value.length > 5 
    }];
}
return self;

The parameter is *valuealready bound to my view model (successfully), and it is updated every time a text field changes.

, , , , , - .

+4
1

-filter: RACObserve(self, value) , YES. , completed value. Bad®.

, !

. value - . , . -map::

RAC(self, completed) = [RACObserve(self, value) map:^(NSString *fieldValue) {
    return @([self validateCurrentValue]);    
}];
+5

Source: https://habr.com/ru/post/1540843/


All Articles