I'm brand new to Swift (quarantine learning) and was following along a YouTube video to create a total price app. I'm having trouble changing a string to a double type, basically taking the input and turning it into a double so I can do math with it.
Here is my code:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBOutlet weak var pricetxt: UITextField!
@IBOutlet weak var taxtxt: UITextField!
@IBOutlet weak var totalpricelbl: UILabel!
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func Calculate(sender: AnyObject) {
let price = Double(pricetxt.text!)!
let tax = Double(taxtxt.text!)!
let totalsalestax = price * tax
let totalprice = price + totalsalestax
totalpricelbl.text = "$\(totalprice)"
}
}
I get an error with these two lines:
let price = Double(pricetxt.text!)!
let tax = Double(taxtxt.text!)!
saying:
"Cannot invoke 'init' with an argument of type '@!value String!'
Running on my Mac 10.9.5 XCode is 6.2 I know these are both old but I can't upgrade my laptop.
Any help is appreciated!