I found a solution to keep the Contact as a struct:
struct Contact: Hashable {
let id: UUID = UUID()
let name: String
var isFavorite = false
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
static func == (lhs: Contact, rhs: Contact) -> Bool {
return lhs.id == rhs.id
}
}
*cell to update: use viewModel instead of contact:
cell.viewModel.isFavorite = self.viewModel.isFavorite
*and toggle the viewModel bool state instead in favoriteAction. toggle on contact.isFavorite doesn't work:
self.viewModel.isFavorite.toggle()