0

I have an array of items (each corresponds to a cell data) and I want to create an array of cell ViewModels.

When I try to map the item to MutablePropery, I get Binary operator '<~' cannot be applied to operands of type 'MutableProperty<[CellViewModel]>' and '[CellViewModel]'

How should I change the below code in order to get reactive stream?

class ListViewModel {
var poiData = MutableProperty([CellViewModel]())

init(poiWrapper: PoiWrapper) {
    self.poiData <~ poiWrapper.poiList.map({ (poiItem)  in
        return CellViewModel(poi: poiItem)
    })
  }
}

My Intention is to create a structure like the one below: From MVVM + ReactiveCocoa. The code I shared is ViewModel of my ViewController, where I tried to create cell ViewModels as soon as initiate my Parent ViewModel. enter image description here

sarawanak
  • 387
  • 1
  • 6
  • 17

1 Answers1

0

If the property is a map of some other signal then it should just be a regular property and not a mutable one and no binding is necessary (ie map returns a property):

class ListViewModel {
    let poiData = Property<[CellViewModel]>

    init(poiWrapper: PoiWrapper) {
        poiData = poiWrapper.poiList.map({ (poiItem)  in
            return CellViewModel(poi: poiItem)
        })
    }
}
Josh Homann
  • 15,933
  • 3
  • 30
  • 33