I have a csv file and I am storing into Sqlite.db
. All is perfectly running in swift. Now I am going to convert .map and forEach to rxSwift.
Everytime I am getting an error cannot assign value of type [CodigoModel]
to publishSubject
.
I am new to RxSwift not getting an idea.
this is my code:
var arrCodigo = PublishSubject<[CodigoModel]>()
self.arrCodigo = arrData.map({ (data) -> CodigoModel in
return CodigoModel.init(data: data)
})
self.arrCodigo.forEach { (obj) in
// store in sqlite db
_ = DBManager.shared.insert(tableName: "codigo_list", dataInDic: [
"cod_distrito": obj.cod_distrito ?? "",
"cod_concelho": obj.cod_concelho ?? "",
"cod_localidade": obj.cod_localidade ?? "",
"nome_localidade": obj.nome_localidade ?? "",
"desig_postal": obj.desig_postal ?? ""])
}
2
Answers
Not familiar with RxSwift, but if it is similar to Combine, you are assigning [CodigoModel] to a publisher.
In Combine it would look something like this.
you would need to setup a subscriber to receive that value.
If I understand the question. Something like this should work:
No need for a subject here. And since you are learning Rx, remember this quote: