So I'm trying to learn swift and on button action, I want to declare a variable as an integer that collects the value from a text field, calculates if it is not nil and prints the value. Why is it asking me to make the variable constant?
This what I've tried
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var enterAge: UITextField!
@IBOutlet weak var catAge: UILabel!
@IBAction func findAge(sender: AnyObject) {
var newage = Int(enterAge.text!)
if newage! == 0
{
var catyears = newage! * 7
catAge.text = "Your cat is \(catyears) in age"
}
else
{
catAge.text = "Please enter a whole number"
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Thanks

newageis never mutated, so there's no need to usevar, making it constant would work fine