-5

I am an android developer and I am learning for Swift now. I am doing the Stanford university CS193P course and trying out some basic calculator program. I followed the instructions but the program doesn't run. It gives me an error.

import UIKit

class ViewController: UIViewController {

        @IBOutlet var display: UIView!




    @IBAction func numberButton(sender:UIButton) {
        let digit = sender.currentTitle
        print("touched \(digit) digit")
    }




}

This is the error

2016-07-03 17:30:10.565 Calculator2[2084:121003] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key button.' * First throw call stack:

Please help and sorry for the noob question.

rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

2

The reason is probably that you have some issue in your nib file. There is an old connection. Try to delete connections properly and if you do not know how to do that, remove your elements from Storyboard, add them again and do the connections. This might happen because if you delete IBOutlets in your .swift file they do not automatically be removed from Storyboard.

Tarvo Mäesepp
  • 4,477
  • 3
  • 44
  • 92
1

Most likely it's because there's something wrong with one of your IBOutlets. Try deleting and re-doing them. Also, be aware that if you delete an IBOutlet in the .swift file, it won't automatically delete it from your .xib or .storyboard, so that's where this problem could come from. Have a look at https://stackoverflow.com/a/8087739/2912892

Community
  • 1
  • 1