Exception NSException * "[<Calculus_area_and_perimeter.ViewController 0x14c506020> setValue: forUndefinedKey:]: this class is not key value coding-compliant for the key calcArea." 0x0000600002799cb0.

I am trying to launch the app, but I get the following error: Exception NSException * "[<Calculus_area_and_perimeter.ViewController 0x14c506020> setValue: forUndefinedKey:]: this class is not key value coding-compliant for the key calcArea." 0x0000600002799cb0.

can anyone help me? how can i solve? Thanks.

Answered by Francesco77 in 690526022

the code:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var larghezzaField: UITextField!

    

    @IBOutlet weak var altezzaField: UITextField!

    

    @IBOutlet weak var result: UILabel!

    

    override func viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view.

    }

  

    @IBAction func TotArea(_ sender: UIButton) {

        if let L = Double(larghezzaField.text!) {

            if let H = Double(altezzaField.text!) {

                result.text = String (L * H)

            } else

                {result}

        }

    }

    @IBAction func calcPerimetro(_ sender: UIButton) {

    }

    @IBAction func cancella(_ sender: UIButton) {

    }

}

What Calculus_area_and_perimeter in ViewController ? Is it an IBOutlet you've defined (looks like, as underscore are Haley used in Swift).

If so, check you have properly connected the IBOutlet to the object in IB.

The way to correct:

  • check you have connected Calculus_area_and_perimeter to its IBOutlet (a label ?)
  • if not, do it
  • if connected, disconnect
  • ,reconnect
  • do a Clean Build Folder
  • possibly quit and relaunch Xcode.

Note: it is not enough to report the error, you should show the code, with all the elements related to the error message. Otherwise we have too much to guess for.

When you get a runtime exception with this message,

"[<Calculus_area_and_perimeter.ViewController 0x14c506020> setValue: forUndefinedKey:]: this class is not key value coding-compliant for the key calcArea." 

iOS runtime is trying to connect an instance declared on storyboard/xib into the @IBOutlet of ViewController named calcArea.

Don't you remember you once connected something to an @IBOutlet and name it calcArea, and then renamed it to something else?

Anyway, you may need to remove the wrong connection pointing calcArea, and re-connect it to the right @IBOutlet.

OK, thank you.

Accepted Answer

the code:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var larghezzaField: UITextField!

    

    @IBOutlet weak var altezzaField: UITextField!

    

    @IBOutlet weak var result: UILabel!

    

    override func viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view.

    }

  

    @IBAction func TotArea(_ sender: UIButton) {

        if let L = Double(larghezzaField.text!) {

            if let H = Double(altezzaField.text!) {

                result.text = String (L * H)

            } else

                {result}

        }

    }

    @IBAction func calcPerimetro(_ sender: UIButton) {

    }

    @IBAction func cancella(_ sender: UIButton) {

    }

}

I have change name from calcArea to totArea but i have = error

Exception NSException * "[&lt;Calculus_area_and_perimeter.ViewController 0x14c506020&gt; setValue: forUndefinedKey:]: this class is not key value coding-compliant for the key calcArea." 0x0000600002799cb0.
 
 
Q