2
 @IBOutlet weak var textBox: UITextField!


@IBOutlet weak var result: UILabel!


@IBAction func calculate(sender: AnyObject) {

var age = textBox.text.toInt()

var Years = age! * 7

    result.text = "your cat is "+ catYears + "cat years old"//cat years is an int who do i print it
}

so after turning textBox into an integer how do i print it in integer form.

Jacob Cafiero
  • 135
  • 1
  • 1
  • 9

2 Answers2

25
result.text = "your cat is \(Years) cat years old"
Mike Cole
  • 1,291
  • 11
  • 19
4

There are two basic ways:

result.text = "Your cat is \(catYears) years old."

result.text = "Your cat is " + catYears.description + " years old."

You can also use NSNumberFormatter, which supports more complex features like thousandths separators and so on:

let formatter = NSNumberFormatter()
formatter.hasThousandSeparators = true
let catYearsString = formatter.stringFromNumber(catYears)

result.text = "Your cat is " + catYearsString! + " years old."
Abhi Beckert
  • 32,787
  • 12
  • 83
  • 110