-1

Why are TextField and Label both considered IBOutlet? One seems to be input the other output.

I am trying to debug an NSUnknownKeyException when XCode simulator is is starting. I am running Steve Derico's TipCalculator exercise and neither my code nor his sample code has build errors but the both report the above error during simulation.

2014-12-29 22:42:32.108 TipCalculator[14401:2353607] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key calculateTapped.'

import UIKit class ViewController: UIViewController {

@IBOutlet weak var billTextField: UITextField!
@IBOutlet weak var tipLabel: UILabel!
@IBOutlet weak var tipRateSegmentedControl: UISegmentedControl!
@IBAction func calculateTapped(sender: AnyObject) {
    var userInput = billTextField.text as NSString
    var totalBill: Float = userInput.floatValue
    var index: Int = tipRateSegmentedControl.selectedSegmentIndex
    var tipRate: Float = 0.10

...series of if's.. var tip: Float = totalBill * tipRate tipLabel.text = "$(tip)" } @TimLewis I edited to show the code

  • Add some code so we can help debug this error. We'll have a hard time otherwise. – Tim Lewis Dec 30 '14 at 16:58
  • @TimLewis I added code by editing the original post. – PhysicsSolutions.com Jan 01 '15 at 16:14
  • possible duplicate of [What does this mean? "'NSUnknownKeyException', reason: ... This class is not key value coding-compliant for the key X"](http://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this-class-is-not-key) – jtbandes Aug 03 '15 at 06:27

1 Answers1

0

Just recreate the button and calculateTapped action and it should work! I got the same error at first and this is how I fixed it!

Good Luck