/ / Pozorujte pole a zložte ho do reťazca - ios, kakao, mvvm, reaktívne kakao

Sledujte pole a zložte ho do reťazca - ios, kakao, mvvm, reaktívne kakao

Som nový v FRP a MVVM, ale zatiaľ to šlo dobre, ale teraz mám problém s pozorovaním poľa na mojom modeli a keď je nastavený, zložte ho na reťazec.

RAC(self, tags) = [[RACObserve(self.deal, tags) sequence] foldLeftWithStart:@"" reduce:^id(NSString *accumulator, NSString *value) {
return [NSString stringWithFormat:@"%@#%@ ", accumulator, value];
}];

Vyššie uvedený kód iba zastaví aplikáciu.

aktualizovať

Takže som na to prišiel, taký typický

RAC(self, tags) = [RACObserve(self.deal, tags) map:^id(NSArray *tags) {
return [[tags rac_sequence] foldLeftWithStart:@"" reduce:^id(NSString *accumulator, NSString *value) {
return [NSString stringWithFormat:@"%@#%@ ", accumulator, value];
}];
}];

Je to však najlepší prístup?

odpovede:

2 pre odpoveď č. 1

A čo toto:

RAC(self, tags) = [RACObserve(self.deal, tags) map:^(NSArray *tags) {
return [@"#" stringByAppendingString:[tags componentsJoinedByString:@"#"]];
}];