Ozvengrad
Ozvengrad

Reputation: 302

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
  }
} 

Upvotes: 0

Views: 63

Answers (1)

luk2302
luk2302

Reputation: 57124

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])"

Upvotes: 3

Related Questions