0

I'm trying to get my UItextField to accept floating point but at the moment, it will only accept an integer. How can I get it to accept floating point in Swift?

class ViewController: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var Swallow13Button: UIButton!

    @IBAction func Swallow13Button (sender: AnyObject) {

            let a:Int? = data1.text.toInt()

            if a > 13.13 {


                self.DimensionLabel.text = "Fail Send DWG For Review"

                self.view.endEditing(true)

            }    

            else {


                self.DimensionLabel.text = "Pass Send DWG for Review"

                self.view.endEditing(true) 
            }

        }
Coder
  • 499
  • 3
  • 13
  • 29

2 Answers2

0

You can convert to float like this

let a = (data1 as NSString).floatValue
Marius Fanu
  • 6,589
  • 1
  • 17
  • 19
0

You can convert using NSString's floatValue:

let a: Float = (data1.text as NSString).floatValue
Armin
  • 1,150
  • 8
  • 24
  • 1
    @Armin, `floatValue` returns a `Float` not an Optional type, so `a` should be of type `Float`. If the string is not valid it will return `0`. – Marius Fanu Feb 02 '15 at 19:10