ios - 观察数组并将其折叠成字符串

标签 ios cocoa mvvm reactive-cocoa

我是 FRP 和 MVVM 的新手,但到目前为止一切顺利,但我现在在观察模型上的数组以及将其设置为字符串时遇到问题。

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

上面的代码只是停止了应用程序。

更新

所以我想通了,很典型

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];
    }];
}];

但这是最好的方法吗?

最佳答案

这个怎么样:

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

关于ios - 观察数组并将其折叠成字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21468681/

相关文章:

ios - 手动ScrollView惯性效果,iOS,Swift

objective-c - "-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object"调用 selectRowIndexes :byExtendingSelection: 时

c# - 当 T 中的属性更改时刷新 ObservableCollection<T> - WPF MVVM

entity-framework - 在许多 ViewModel 中需要从数据库中获取相同类型的数据

WPF 绑定(bind) MVVM 中验证装饰器的可见性

javascript - 是否有移动 Safari 全屏 Javascript 事件?

ios - 如何从 AVPlayer 中提取整个流标题?

objective-c - 从 xcode 中删除 "Format String is not a string literal"警告

xcode - Cocoa:如何让 child 适合 parent ?

swift - NSCollectionViewFlowLayout collectionViewContentSize 更新但 Collection View 框架不更新