convertir TextField a Int

 

 

class BMICalculator: UIViewController {
    //MARK: Properties
    @IBOutlet weak var weightField: UITextField!
    @IBOutlet weak var heightField: UITextField!
    @IBOutlet weak var solutionTextField: UILabel!

    @IBAction func calcButton(_ sender: AnyObject) {
    let weightInt = Int((weightField?.text!)!)
    let heightInt = Int((heightField?.text!)!)

    let solution = weightInt!/(heightInt!*heightInt!)

    solutionTextField?.text = "\(solution)"
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

https://stackoverflow.com/questions/39728587/how-to-get-integer-values-from-text-fields-in-swift

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *