tacos_tacos_tacos
tacos_tacos_tacos

Reputation: 10585

Reactive(Cocoa) or otherwise approach to mapping a producer whose map function depends on another producer

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 AnnotationOccurrences 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:

Any help is appreciated!

Upvotes: 0

Views: 49

Answers (0)

Related Questions