Trying to pull a number from a Field and keep getting Optional(number) instead of the number
@IBOutlet weak var years: UITextField!
@IBAction func calculateYear
toInt()
returns an optional because the conversation to an integer can fail. Consider the case where the user enters something other than a number. When the user enters "Blah", what do you expect toInt()
to return?
You need to conditionally unwrap the optional
if let a = years.text.toInt() {
println(a)
}