I have a list of models that I fetch from a server, and basically I get array of these:
struct ContactModel: Codable, Equatable {
static func == (lhs: ContactModel, rhs: ContactModel) -> Bool {
return lhs.name == rhs.name &&
lhs.avatar == rhs.avatar &&
lhs.job == rhs.job &&
lhs.follow == rhs.follow
}
let id: Int
let name: String
let avatar:String?
let job: JobModel?
let follow:Bool
enum CodingKeys: String, CodingKey {
case id, name, avatar, job, follow
}
}
So I want to show a list of contacts in my tableview
.
Now I have this struct as well which is wrapper around this model:
struct ContactCellModel : Equatable, IdentifiableType {
static func == (lhs: ContactCellModel, rhs: ContactCellModel) -> Bool {
return lhs.model == rhs.model
}
var identity: Int {
return model.id
}
var model: ContactModel
var cellIdentifier = ContactTableViewCell.identifier
}
What I am trying to do, is to create datasource using RxDatasources
, and bind to it, like this(ContactsViewController.swift):
let dataSource = RxTableViewSectionedAnimatedDataSource<ContactsSectionModel>(
configureCell: { dataSource, tableView, indexPath, item in
if let cell = tableView.dequeueReusableCell(withIdentifier: item.cellIdentifier, for: indexPath) as? BaseTableViewCell{
cell.setup(data: item.model)
return cell
}
return UITableViewCell()
})
but I am not sure what I should do right after. I tried something like this:
Observable.combineLatest(contactsViewModel.output.contacts, self.contactViewModel.changedStatusForContact)
.map{ (allContacts, changedContact) -> ContactsSectionModel in
//what should I return here?
}.bind(to: dataSource)
I use combineLatest
, cause I have one more observable (self.contactViewModel.changedStatusForContact
) that notifies when certain contact has been changed (this happens when you tap a certain button on a contact cell).
So what should I return from .map above in order to successfully bind to previously created dataSource
?