0

抱歉,如果这是一个非常基本的问题,但我有点精神错乱。我可能会通过作弊来继续 - 引入 -foreach风格的循环或其他东西 - 但它会破坏目的。

我正在学习ReactiveCocoa特别和一般的概念。

我想AnnotationView用一个单曲制作一个UITextView显示由和组成的NSAttributedString构建。AnnotationViewModelannotatedText: StringannotationTags: [AnnotationTags]

反过来AnnotationTags实际上是AnnotationOccurrence特定标签的所有 s 的集合。例如,如果我们注释“the”这个词,我们最终可能会AnnotationOccurrences为“the”这个词添加许多但只有一个标签。

class DocumentAnalysisViewModel {

    let propertyText: MutableProperty<String>
    let propertyTags: MutableProperty<[AnnotationTagViewModel]>

    init(_ text: String, _ tags: [AnnotationTagViewModel]) {
        self.propertyText = MutableProperty(text)
        self.propertyTags = MutableProperty(tags)
    }

}

反正...

定义an 的方式AnnotationOccurrence- 由开始/结束索引(仅一对) -OccurrenceannotatedText.

因此,要格式化NSAttributedString,我需要AnnotationTags,,因此我需要annotatedText在提供标签的同时使用 。

这个小问题暴露了我对 ReactiveCocoa 和这个模式的理解不够深入。我尝试执行以下操作,但由于各种原因,每次都在中途或更早停止:

  • vm.propertyTags.producer.combineLatestWith(vm.propertyText.producer)map- 显然,如果不将每个格式都采用一种通用格式,例如一个元组,就无法编译(String, [AnnotationViewModel])-我停止了,因为它感觉笨拙和错误。
  • 映射整个对象或MutableProperty为整个对象创建一个(DocumentAnalysisViewModel) - **再次,感觉不对,因为即使在这种情况下更好,我也没有学习如何处理反应式设计中肯定是常见的需求)

任何帮助表示赞赏!

4

0 回答 0