Error: This property is defined but not available in this context
I have created a file with the fields of the Sqlite database but I cannot access the properties from the tableView
DataTableWord.swift
class DataTableWord{
var idWord: Int = 0
var word: String = ""
var features: String = ""
var number: Int = 0
init(idWord: Int, word: String, features: String, number: Int) {
self.idWord = idWord
self.word = word
self.features = features
self.number = number
}
}
ViewController.swift
import UIKit
class ViewController: UIViewController, UITextViewDelegate, UITableViewDataSource {
var dataTableWord: [DataTableWord] = []
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataTableWord.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "idCell1Main1", for: indexPath) as! TableViewCell
cell.cellLabelNumber.text = dataTableWord.[indexPath.row].idWord
return cell
}
}
Why this error message?
Type of idWord
is Int
but cell.cellLabelNumber.text
is a string . You can not equalize that two different kind.
Change
cell.cellLabelNumber.text = dataTableWord[indexPath.row].idWord
With:
cell.cellLabelNumber.text = "\(dataTableWord[indexPath.row].idWord)"