"Je ne connais pas encore FRP et MVVM, mais jusqu’à présent, tout s’est bien passé, mais j’ai maintenant un problème pour observer un tableau sur mon modèle et, quand il est défini, le replier en chaîne.
RAC(self, tags) = [[RACObserve(self.deal, tags) sequence] foldLeftWithStart:@"" reduce:^id(NSString *accumulator, NSString *value) {
return [NSString stringWithFormat:@"%@#%@ ", accumulator, value];
}];
Le code ci-dessus ne fait que suspendre l'application.
Mettre à jour
Alors je l'ai compris, si typique
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];
}];
}];
Mais est-ce la meilleure approche?
Réponses:
2 pour la réponse № 1Que dis-tu de ça:
RAC(self, tags) = [RACObserve(self.deal, tags) map:^(NSArray *tags) {
return [@"#" stringByAppendingString:[tags componentsJoinedByString:@"#"]];
}];