I am trying to display a checkmark next to favourited reports in my project. I save the title into Core Data successfully and fetch them successfully too. I load them into an array called favourite. I then compare against the title loaded into the cell.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
guard let cell = tableView.dequeueReusableCell(withIdentifier: "CellClass") as? CellClass else { return UITableViewCell()}
cell.titleLbl.text = objArray[indexPath.section].sectionObj?[indexPath.row].title ?? "no title"
cell.descLbl.text = objArray[indexPath.section].sectionObj?[indexPath.row].authors ?? "no authors"
if (self.favourite.count > 0)
{
for i in 0...self.favourite.count - 1
{
if (objArray[indexPath.section].sectionObj?[indexPath.row].title == favourite[i].title!)
{
cell.accessoryType = .checkmark
}
}
}
return cell
}
Currently, I only have one piece of data in Core Data so one checkmark should be shown but it seems there is a recursive pattern of every 10 cells in my table view.