Ocorre um erro quando tendo converter o valor da variável happiness de 'String' para 'Int'.
Erro: Value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?
segue o código.
import UIKit
class ViewController: UIViewController {
@IBOutlet var nameField: UITextField?
@IBOutlet var happinessField: UITextField?
@IBAction func add(){
if nameField == nil || happinessField == nil {
return
}
let name = nameField!.text
let happiness = happinessField!.text.toInt()
if happiness == nil {
return
}
let meal = Meal(name: name, happiness: happiness!)
println("eaten: \(meal.name) \(meal.happiness)")
}
}