0

So im trying to learn Swift and used a video to build my first app after learning a bit with Hackingwithswift 100 days Swift. I made everything like in the video, but still get an error im not capable of handling. Maybe one of you could help!

I get this Error: Thread 1: Exception: "[<SalesTax.ViewController 0x7fb0cec08d30> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key pricetxt."

This is my code:

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var priceTxt: UITextField!
@IBOutlet weak var salesTaxTxt: UITextField!
@IBOutlet weak var totalPriceLbl: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()
    totalPriceLbl.text = ""
}

@IBAction func calculateTotalPrice(_ sender: Any) {
    let price = Double(priceTxt.text!)!
    let salesTax = Double(salesTaxTxt.text!)!
    
    let totalSalesTax = price * salesTax
    let totalPrice = price + totalSalesTax
    totalPriceLbl.text = "$\(totalPrice)"
}

}

the compiler only shows the error after im trying to run it. The emulator starts, but the app keeps blank (just a white page)

  • `pricetxt` vs `priceTxt`. I guess you renamed that variable, no? The storyboard part is looking for one with a lowercase "t", and it doesn't exist (anymore). So remove the link, and redo it with the new one. – Larme Jul 11 '20 at 16:41
  • Ok will do that! Yes indeed I renamed it to make it fit more into the whole "concept". So the only way to handle this in the future is to stick with the names I gave them and not renaming them? – xadrus1799 Jul 11 '20 at 16:45
  • If you changed the name of a part of code (class name, variable name) that is linked with Interface, redo it – Larme Jul 11 '20 at 17:11

0 Answers0