I have 2 coredata arrays. One has 3 elements and the other one also has 3 elements. Now I want to load in my tableview both these arrays. So I'll have a total of 6 rows in my tableview.
This I have achieved like so...
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let totalCount = (customerDetails.count) + (customerDetails2.count)
return totalCount
}
And the data of these two arrays I tried loading like so in the cellForRowAt...
let customers = customerDetails[indexPath.row] //CRASHES HERE
for i in 0..<(customerDetails.count) {
cell.nameLabel.text = customers.fname
if i == customerDetails.count {
break
}
}
let customers2 = customerDetails2[indexPath.row]
for i in 0..<(customerDetails2.count) {
cell.nameLabel.text = customers2.fname
if i == customerDetails2.count {
break
}
}
But it crashes at the line mentioned saying Index out of range possibly because customerDetails has only 3 rows while the total cells loaded is 6.
What can be done in such a case..?