I am working on expandable tableView where I need to add or remove the objects based on didSelectRowAtIndexpath. I was able to add the selected item into an array but the problem is when I am trying to remove the selection from array.
This is the error I am getting:
cannot invoke index with an argument list of type (of:any)
Here is my code:
func expandableTableView(_ expandableTableView: LUExpandableTableView, didSelectRowAt indexPath: IndexPath) {
let selectedService = arrData[indexPath.section].Children?[indexPath.row].EnglishName ?? ""
let inPrice = arrData[indexPath.section].Children?[indexPath.row].InPrice ?? 0
print("service and price : \(selectedService) \(inPrice)")
let selectedItem = (" \(selectedService) \(inPrice)")
let cell: UITableViewCell? = expandableTableView.cellForRow(at: indexPath)
if cell?.accessoryType == UITableViewCellAccessoryType.none
{
cell?.accessoryType = UITableViewCellAccessoryType.checkmark
selectionArr.append(selectedItem)
}
else
{
cell?.accessoryType = UITableViewCellAccessoryType.none
selectionArr.remove(at: selectionArr.index(of: selectedItem)!)
}
print(selectionArr)
}
selectionArr?[Any]causes the issue. DeclareselectionArrto something more specific. It seems to be an array of string, so[String].