0

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

1 Answer 1

3

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])"
Sign up to request clarification or add additional context in comments.

2 Comments

what if the output keeps coming up as an optional, How can I unwrap it
@Karpisdiem either use an if-let around it, or use the ?? operator

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.