My code which contains a tableview where I am trying to compare two values from one struct it's giving me total number of array while its even printing the compared data which contains even extra cell that is not required. I want to compare cellID and cellID2 values if they match then it should print only those cells !!! Can someone help me with this error
import UIKit
struct One {
let cellID: String
let name: String
let lastName: String
let cellID2: String
}
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var arrayOne = [One(cellID: "1", name: "hello", lastName: "hello last", cellID2: "1"), One(cellID: "1", name: "hello", lastName: "hello last", cellID2: "1"), One(cellID: "1", name: "hello", lastName: "hello last", cellID2: "2"), One(cellID: "1", name: "hello", lastName: "hello last", cellID2: "1"), One(cellID: "1", name: "hello", lastName: "hello last", cellID2: "2"), One(cellID: "1", name: "hello", lastName: "hello last", cellID2: "1")]
@IBOutlet weak var compareTableView: UITableView!
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrayOne.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CompareTableViewCell") as! CompareTableViewCell
let arrayID = arrayOne[indexPath.row]
if arrayID.cellID == arrayID.cellID2{
cell.lblOne.text = arrayID.cellID
cell.lblTwo.text = arrayID.cellID2
cell.lblThree.text = arrayID.lastName
cell.lblFour.text = arrayID.name
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80
}
}