Karpisdiem Karpisdiem - 13 days ago 7
iOS Question

Multidimensional Array output to label

Hi I'm having problems printing it to the label which is the output.text, it keeps coming out blank, but when I print to console it shows the number.

name.state = stateText.text

var stateName = [
["AK - Alaska", tax.alaska!],
["AL - Alabama", tax.alabama!],
["AR - Arkansas", tax.arkansas!],
["AZ - Arizona", tax.arizona!],
["CA - California", tax.california!]
]

for var i = 0; i < stateName.count; i++ {
if tax.state == stateName[i][0] {
stateName[i][1] = Double(taxNumb.text!)!
print(stateName[i][1])
output.text = stateName[i][1] as? String
}
}

Answer

Don't cast to String. What you have is a Double, that is not just castable to String.
You need to create a String:

output.text = String(stateName[0][1])

or

output.text = "\(stateName[i][1])"