First, I have a struct like this:
struct CodigosAutorizacion {
var codigo: String?
var codigoCancel: String?
var codigoSitio: String?
var codigoCancelsitio: String?
var instancia: String?
init(
code : String? = nil,
codeCancel: String? = nil,
codeSite: String? = nil,
codeSiteCancel: String? = nil,
instance: String? = nil
){
self.codigo = code
self.codigoCancel = codeCancel
self.codigoSitio = codeSite
self.codigoCancelsitio = codeSiteCancel
self.instancia = instance
}
}
This structure values are filled from a web service, then is stored in a array like this:
let codeArray = [
CodigosAutorizacion(
code: validateData!["codigo"] as? String,
codeCancel: validateData!["cancela_codigo"] as? String,
codeSite: validateData!["cod_sitio"] as? String,
codeSiteCancel: validateData!["cancela_cod_sitio"] as? String,
instance: validateData!["instancia"] as? String)
]
codes?.append(codeArray)
now, when I try to give those values to a label inside a table cell(I use a custom cell), I cant access the specific structure value to give to the label. Example of what I am saying
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let codeCell: DetalleCodigoCell = tableView.dequeueReusableCell(withIdentifier: "CodigoCell", for: indexPath) as! DetalleCodigoCell
codeCell.CodigoNombre.adjustsFontSizeToFitWidth = true
codeCell.codigoNombre.text = codes![indexPath.row].instancia
codeCell.codigoSitio.text = codes![indexPath.row].codigoSitio
codeCell.codigoCancelSitio.text = codes![indexPath.row].codigoCancelsitio
codeCell.codigoInstancia.text = codes![indexPath.row].codigo
codeCell.codigoCancelInstancia.text = codes![indexPath.row].codigoCancel
return codeCell
}
I get the following errors in lines 'codes![indexPath.row].instancia' for example
errors:
-No exact matches in call to subscript
-Reference to member 'instancia' cannot be resolved without a contextual type
I have try accessing directly from 'codeArray' instead of storing it in the intermediate global array 'codes' and accessing but it doesn't work either, as I know this is suppose to be posible but I don't know why I am getting that error. Any solution? Thanks in advance.
This is a reference for what I am trying to do: How to pass specific value to a cell when that cell is selected?