i have an array of model class and this model class have an array . i want to populate tableview from array . its showing me error
Here is my Model class
class DataModel {
var name:[String]
init(name:[String]) {
self.name = name
}
}
Here is my model object :
class Data {
static var product = [DataModel]()
}
Here is my function for append data to object :
class Function {
static func read(compleationHandler:@escaping ()->()) {
var model = ["nsu","iUB","UIU"]
DispatchQueue.global(qos: .userInteractive).async {
if Data.product.count == 0 {
Data.product.append(DataModel(name: model))
}
DispatchQueue.main.async {
compleationHandler()
}
}
}
}
and here is my tableView Cell method :
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = myTableView.dequeueReusableCell(withIdentifier: "myCell") as! myCell
cell.textLabel?.text = Data.product[indexPath.row].name[indexPath.count]
return cell
}
Here is my ViewDidLoad :
myTableView.delegate = self
myTableView.dataSource = self
Function.read { [weak self] in
print(Data.product.count)
self?.myTableView.reloadData()
}
}