ios - RACObserve(), RAC() - how to set a BOOL value based on an NSString -
being reactivecocoa newbie, i'm hoping advice this:
i'm trying create dynamic form contains multiple field objects parsed xml file. each field can have muliple validation rules run against field's nsstring *value
param.
for rac part of question-
inside each field object, want bind bool completed
signal checks field's *value
param against array of rules. far i've gotten here thinking:
@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 watch values here, no luck nslog(@"%s::fieldvalue = %@\n", sel_getname(_cmd), fieldvalue); // same here, i'd able view `*value` here far no luck return [self validatecurrentvalue]; // method checks value.length > 5 }]; } return self;
the *value
param has been bound view model (successfully) , gets updated each time textfield changes.
what i'm looking basic example or best-practice, code above crashes when run know i'm missing fundamental.
thanks all
-filter:
passing values racobserve(self, value)
through unchanged, if block returns yes
. means you're trying set completed
values of whatever type value
is. that's bad®.
but news you're close!
instead of filtering, want transform. want take every value
, map other thing. namely whether value passes validation. that, use -map:
:
rac(self, completed) = [racobserve(self, value) map:^(nsstring *fieldvalue) { return @([self validatecurrentvalue]); }];
Comments
Post a Comment