0

I can't believe I'm having a problem with the very first lecture! We are building a calculator (it is not at all functional as a calculator at this point). Mine was working just fine until the performOperation function was added. Now I'm getting "this class is not key value coding compliant" error. The thing is that, as far as I can see, my code EXACTLY replicates the code that he is using in the class. I must be missing something but I've checked roughly 50 times to find a difference and I can't find one. Help? It is crashing every time.

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var display: UILabel!

var userIsInTheMiddleOfTyping = false

@IBAction func touchDigit(sender: UIButton) {
    let digit = sender.currentTitle!

    if userIsInTheMiddleOfTyping {
        let textCurrentlyInDisplay = display.text!
        display.text = textCurrentlyInDisplay + digit
    } else {
        display.text = digit
    }

    userIsInTheMiddleOfTyping = true
}


@IBAction func performOperation(sender: UIButton) {
    userIsInTheMiddleOfTyping = false
    if let mathematicalSymbol = sender.currentTitle {
        if mathematicalSymbol == "π" {
            display.text = String(M_PI)
        }
    }
}

}

EDIT: Code format

4
  • I think it would be helpful if you can include a screenshot of your calculator that you created using Interface Builder. Your code looks fine to me. Also, when do you get this error ? After pressing a button ? Commented Sep 7, 2016 at 4:46
  • Please take care when posting here. Edit your title to describe precisely the nature of your question. Stack Overflow is meant to be more of a Wikipedia of programming questions than a free-flowing discussion group. Commented Sep 7, 2016 at 5:56
  • The error you are getting happens if you rename or delete an @IBOutlet in your code. Click on your ViewController in the storyboard and then check your connections in the Connections Inspector in the right panel of Xcode. An unconnected outlet will have a ! Next to it. Delete that connection by clicking on the x next to it and try connecting it again. Commented Sep 7, 2016 at 9:35
  • Thank you vacawama! I checked and I'm not seeing any ! to indicate an error. Suhaib, the error occurs when I try to run the simulator ... so I have no screen shot of it to share. Commented Sep 7, 2016 at 11:35

1 Answer 1

1

You can check your viewcontroller in storyboard, at the Module TextField in the right toolbar.

Do following steps if module textfield is empty (there’s no placeholder):

  • Step 1. Focus Module TextField
  • Step 2. Edit randomly then clear
  • Step 3. Press Enter, if the result is as same as this picture, everything’s going okey.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! Unfortunately it was already connected properly to the calculator so that wasn't the problem.
I met this problem before in spite of properties connected. I guess it's caused by xcode's bug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.