Reputation: 10585
Apologies if this is a very basic question but I am a bit mentally stuck. I could probably proceed by cheating - introducing a foreach
-style loop or something - but it would defeat the purpose.
I am learning ReactiveCocoa
in particular and the concept in general.
I want to make an AnnotationView
with a single UITextView
that displays an NSAttributedString
built from an AnnotationViewModel
consisting of annotatedText: String
and annotationTags: [AnnotationTags]
.
The AnnotationTags
in turn is really a collection of all the AnnotationOccurrence
s for a specific label. For instance, if we annotated the word "the," we'd probably end up with many AnnotationOccurrences
but just one tag for the word "the."
class DocumentAnalysisViewModel {
let propertyText: MutableProperty<String>
let propertyTags: MutableProperty<[AnnotationTagViewModel]>
init(_ text: String, _ tags: [AnnotationTagViewModel]) {
self.propertyText = MutableProperty(text)
self.propertyTags = MutableProperty(tags)
}
}
Anyway...
The way that an AnnotationOccurrence
is defined - by start/end indices (just one pair) - tightly marries the Occurrence
with the annotatedText
.
So, to format the NSAttributedString
, I need the AnnotationTags,
and so in turn I need the annotatedText
at the same time I am providing the tags.
This little problem has exposed my lack of depth in understanding ReactiveCocoa and this pattern in general. I tried doing the following, but stopped midway or earlier each time for various reasons:
vm.propertyTags.producer.combineLatestWith(vm.propertyText.producer)
-obviously won't compile without a map
taking each to a common format, say, a tuple of (String, [AnnotationViewModel])
- I stopped because it felt clumsy and wrong.MutableProperty
for the entire object (the DocumentAnalysisViewModel
) - **again, felt wrong, because even if it is better in this case, I am not learning how to handle what is surely a common need in Reactive design)Any help is appreciated!
Upvotes: 0
Views: 49