I want to find the array index of the selected element in a table and assign it to a variable.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
let kategorilerVC = KategoriController()
let kategoriIndexCode = firstList[indexPath.row]
print(kategoriIndexCode)
CodePudding user response:
The array index is indexPath.row
, which is the same variable you are using to access the value of the array when you do this:
firstList[indexPath.row]
So in your code, you could do this:
let kategoriIndexCode = indexPath.row