Siddharth Hemrajani Siddharth Hemrajani - 1 year ago 48
Swift Question

Swift-iOS program doesn't run

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.

Answer Source

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.