creating button that plays sound, getting NSException error - ios

import UIKit
import AVFoundation
import AudioToolbox
class ViewController: UIViewController {
var player : AVAudioPlayer?
func playSound(){
let path = Bundle.main.path(forResource: "Roblox", ofType:"mp3")!
let url = URL(fileURLWithPath: path)
do {
let sound = try AVAudioPlayer(contentsOf: url)
self.player = sound
sound.numberOfLoops = 1
sound.prepareToPlay()
sound.play()
} catch {
print("error loading file")
// couldn't load file :(
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func button(_ sender: Any) {
playSound()
}
}
Hello, I am trying to make a button that plays a sound (Roblox.mp3). It compiles without errors. However, when I open the simulator, it crashes. My error log is:
2017-08-10 20:52:57.876 Oof[2500:252563] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Oof.ViewController 0x7fc320607800> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key button.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010dcd6b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010aa8a141 objc_exception_throw + 48
2 CoreFoundation 0x000000010dcd6a59 -[NSException raise] + 9
3 Foundation 0x000000010a5a000b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
4 UIKit 0x000000010b0f7994 -[UIViewController setValue:forKey:] + 87
5 UIKit 0x000000010b364a09 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x000000010dc7ce8d -[NSArray makeObjectsPerformSelector:] + 269
7 UIKit 0x000000010b3633bf -[UINib instantiateWithOwner:options:] + 1856
8 UIKit 0x000000010b0fdfc3 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x000000010b0fe8d9 -[UIViewController loadView] + 177
10 UIKit 0x000000010b0fec0a -[UIViewController loadViewIfRequired] + 195
11 UIKit 0x000000010b0ff45a -[UIViewController view] + 27
12 UIKit 0x000000010afc798a -[UIWindow addRootViewControllerViewIfPossible] + 65
13 UIKit 0x000000010afc8070 -[UIWindow _setHidden:forced:] + 294
14 UIKit 0x000000010afdaebe -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x000000010af5437f -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4346
16 UIKit 0x000000010af5a5e4 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1709
17 UIKit 0x000000010af577f3 -[UIApplication workspaceDidEndTransaction:] + 182
18 FrontBoardServices 0x00000001111765f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
19 FrontBoardServices 0x000000011117646d -[FBSSerialQueue _performNext] + 186
20 FrontBoardServices 0x00000001111767f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x000000010dc7cc01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
27 Oof 0x000000010a1429b7 main + 55
28 libdyld.dylib 0x0000000110b2d65d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I am really not sure what is going wrong. I believe the sound I want is imported into Xcode because I drag and dropped it into my project. If the error is with the line that requests the sound, I may not have formatted it properly. I have seen it as both #"mp3" and typeOf("mp3"). Again, sorry if this seems rudimentary. I am just beginning with swift, and there are some...langauge barriers that I am struggling with.

Open your storyboard and goto Connection inspector you can see something like below screenshot.
#IBOutlet connection is binded but unknown to storyboard. this might be one reason of crashing your application.

Related

My app won't run... because of an unchanged AppDelegate?

My app was working perfectly until I added an #IBAction. Now I just get this error:
2017-06-09 07:55:35.285 Press[1594:102051] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key add.'
* First throw call stack:
(
0 CoreFoundation 0x000000010724bb0b exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001044f3141 objc_exception_throw + 48
2 CoreFoundation 0x000000010724ba59 -[NSException raise] + 9
3 Foundation 0x0000000104008e8b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
4 UIKit 0x0000000104b60644 -[UIViewController setValue:forKey:] + 87
5 UIKit 0x0000000104dcd6b9 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001071f1e8d -[NSArray makeObjectsPerformSelector:] + 269
7 UIKit 0x0000000104dcc06f -[UINib instantiateWithOwner:options:] + 1856
8 UIKit 0x0000000104b66c73 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x0000000104b67589 -[UIViewController loadView] + 177
10 UIKit 0x0000000104b678ba -[UIViewController loadViewIfRequired] + 195
11 UIKit 0x0000000104b6810a -[UIViewController view] + 27
12 UIKit 0x0000000104a3063a -[UIWindow addRootViewControllerViewIfPossible] + 65
13 UIKit 0x0000000104a30d20 -[UIWindow _setHidden:forced:] + 294
14 UIKit 0x0000000104a43b6e -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x00000001049bd31f -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4346
16 UIKit 0x00000001049c3584 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1709
17 UIKit 0x00000001049c0793 -[UIApplication workspaceDidEndTransaction:] + 182
18 FrontBoardServices 0x000000010895b5f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24
19 FrontBoardServices 0x000000010895b46d -[FBSSerialQueue _performNext] + 186
20 FrontBoardServices 0x000000010895b7f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x00000001071f1c01 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
22 CoreFoundation 0x00000001071d70cf __CFRunLoopDoSources0 + 527
23 CoreFoundation 0x00000001071d65ff __CFRunLoopRun + 911
24 CoreFoundation 0x00000001071d6016 CFRunLoopRunSpecific + 406
25 UIKit 0x00000001049bf02f -[UIApplication _run] + 468
26 UIKit 0x00000001049c50d4 UIApplicationMain + 159
27 Press 0x0000000103f1a877 main + 55
28 libdyld.dylib 0x00000001081eb65d start + 1
29 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
This is my Viewcontroller code:
import UIKit
class ViewController: UIViewController {
// OUTLETS
#IBOutlet weak var score: UILabel!
#IBAction func add(_ sender: Any) {
add()
}
// VARIABLES
var scoreVar = 0
let levelUpAt = [50, 100, 500, 1000, 5000, 10000, 50000, 100000]
var currentLevel = 1
var toAdd = 1
// OVERRIDES
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
// FUNCTIONS
// Below code adds to the score
func add() {
scoreVar += 1 // Adds 1 to scoreVar
score.text = "scoreVar"; // Updates text to match
checkForLevelUp(); // Calls the function defined in the next few days ago
}
// Below code checks if the score meets the next level requirements
func checkForLevelUp() {
if (scoreVar - 1 < levelUpAt[currentLevel - 1]) { // Complicated math-y if statment
currentLevel += 1
toAdd += 1
}
}
}
It seems to be stuck on the class AppDelegate: UIResponder, UIApplicationDelegate { line on the AppDelegate, according to the debugger.
Go to your story board and click on the ViewController. Click one the Add button you created.
On the right side in the Outlet Inspector, remove anything mentioning the "Add" button.
Finally, recreate the outlets by option dragging from the button to your view controller and setting the type to "Action".

Why "Unknown class"?

I am a beginner in programming, and new to Stack Overflow as well. I'm still figuring out how codes and this website work, so I'm sorry if I didn't use them correctly. (I'm not a native English speaker, but I'll do my best to explain my question as well as possible)
I'm using Xcode Version 8.1, and Swift.
I'm building an app for my school project. I've already created To-Do-List App and Countdown Timer App. So, I want to put them together in one app now.
I created a new project and inserted Tab Bar Controller. Then copied all the files I used in To-Do-List and Countdown Timer apps, and set up the storyboard.
There are no caution marks, but when I run the simulator, an error comes up and the simulator stops. The error I got is "Thread 1: signal SIGABRT" in this line in AppDelegate.swift:
class AppDelegate: UIResponder, UIApplicationDelegate {
and the message in the console is:
2017-01-06 20:32:22.207 PP Final App[61701:3259153] Unknown class PomodoroViewController in Interface Builder file.
2017-01-06 20:32:22.713 PP Final App[61701:3259153] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fd7faf075d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key lbTimer.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001100c234b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010fb2321e objc_exception_throw + 48
2 CoreFoundation 0x00000001100c2299 -[NSException raise] + 9
3 Foundation 0x000000010f63326f -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
4 UIKit 0x000000011067f4ef -[UIViewController setValue:forKey:] + 88
5 UIKit 0x00000001108f379e -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x0000000110067590 -[NSArray makeObjectsPerformSelector:] + 256
7 UIKit 0x00000001108f2122 -[UINib instantiateWithOwner:options:] + 1867
8 UIKit 0x0000000110685c21 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
9 UIKit 0x0000000110686543 -[UIViewController loadView] + 177
10 UIKit 0x0000000110686878 -[UIViewController loadViewIfRequired] + 201
11 UIKit 0x00000001106870cc -[UIViewController view] + 27
12 UIKit 0x00000001106e52df -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 483
13 UIKit 0x00000001106e4721 -[UITabBarController transitionFromViewController:toViewController:] + 59
14 UIKit 0x00000001106e05e2 -[UITabBarController _setSelectedViewController:] + 365
15 UIKit 0x00000001106e0464 -[UITabBarController setSelectedViewController:] + 234
16 UIKit 0x000000011059e6e6 +[UIView(Animation) performWithoutAnimation:] + 90
17 UIKit 0x00000001106daa00 -[UITabBarController _selectDefaultViewControllerIfNecessaryWithAppearanceTransitions:] + 354
18 UIKit 0x00000001106dbb7a -[UITabBarController viewWillAppear:] + 206
19 UIKit 0x000000011068ca0f -[UIViewController _setViewAppearState:isAnimating:] + 692
20 UIKit 0x000000011068d11f -[UIViewController __viewWillAppear:] + 147
21 UIKit 0x000000011068e913 -[UIViewController viewWillMoveToWindow:] + 507
22 UIKit 0x0000000110595151 -[UIView(Hierarchy) _willMoveToWindow:withAncestorView:] + 621
23 UIKit 0x00000001105a5cf0 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 451
24 UIKit 0x00000001105947a1 -[UIView(Hierarchy) addSubview:] + 838
25 UIKit 0x0000000110550f5b -[UIWindow addRootViewControllerViewIfPossible] + 849
26 UIKit 0x00000001105513a2 -[UIWindow _setHidden:forced:] + 293
27 UIKit 0x0000000110564cb5 -[UIWindow makeKeyAndVisible] + 42
28 UIKit 0x00000001104ddc89 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4818
29 UIKit 0x00000001104e3de9 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
30 UIKit 0x00000001104e0f69 -[UIApplication workspaceDidEndTransaction:] + 188
31 FrontBoardServices 0x0000000113ed3723 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
32 FrontBoardServices 0x0000000113ed359c -[FBSSerialQueue _performNext] + 189
33 FrontBoardServices 0x0000000113ed3925 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
34 CoreFoundation 0x0000000110067311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
35 CoreFoundation 0x000000011004c59c __CFRunLoopDoSources0 + 556
36 CoreFoundation 0x000000011004ba86 __CFRunLoopRun + 918
37 CoreFoundation 0x000000011004b494 CFRunLoopRunSpecific + 420
38 UIKit 0x00000001104df7e6 -[UIApplication _run] + 434
39 UIKit 0x00000001104e5964 UIApplicationMain + 159
40 PP Final App 0x000000010f52c1cf main + 111
41 libdyld.dylib 0x000000011373c68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
In this message, I see "Unknown class PomodoroViewController in Interface Builder file." This is the problem, right? But I don't know why I got this message. Are there any problems in the file?
Is the way I use Tab Bar Controller right?
Here's the code file of Pomodoro View Controller:
PomodoroViewController
import UIKit
class PomodoroViewController: UIViewController {
#IBOutlet weak var lbTimer: UILabel!
let pomodoroTime: TimeInterval = 60 * 25 //Pomodoro Timer 25 minutes
let formatter = DateFormatter()
var theTime: TimeInterval = 0.0
override func viewDidLoad(){
super.viewDidLoad()
formatter.dateFormat = "mm:ss"
let startTime = Date(timeIntervalSinceReferenceDate: pomodoroTime)
lbTimer.text = formatter.string(from: startTime)
}
override func didReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
}
#IBAction func countDown(_ sender: UIButton) {
theTime = pomodoroTime
Timer.scheduledTimer(timeInterval: 1.0,
target: self,
selector: #selector(PomodoroViewController.tickTimer(timer:)),
userInfo: nil,
repeats: true)
}
func tickTimer(timer: Timer){
theTime -= 1.0
let newTime = Date(timeIntervalSinceReferenceDate: theTime)
if theTime < 0.1 {
timer.invalidate()
}
}
}
and this is how the storyboard looks like:
storyboard
What this error means is:
You have a storyboard (or maybe a xib) that says that one of the view controllers is a PomodoroViewController. But...
PomodoroViewController does not exist when the app is running.
The message says that iOS tried to find PomodoroViewController but it wasn't there, so it tried to use UIViewController instead. Except UIViewController doesn't have the lbTimer property, which makes the app crash.
There are a couple of reasons this could happen:
You might have forgotten to copy PomodoroViewController to the new project.
If you did copy it, you might not be including it in the app target. [Files can be included in the Xcode project that don't get compiled, because you might use the same project file for more than one target.]
In the second case, make sure that the file is checked in the file inspector on the right side of the Xcode window:

Swift Stopwatch App crashing, don't know where I'm going wrong

I am trying to make a stopwatch app for a coding class I am taking. I have no errors before I run the code, but once I run it it crashes after "build succeeds".
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
var timer = NSTimer()
var count = 0
func updateTime() {
count++
timeLabel.text = "\(count)"
}
#IBOutlet weak var timeLabel: UILabel!
#IBAction func playButton(sender: AnyObject) {
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("updateTime"), userInfo: nil, repeats: true)
}
#IBAction func pauseButton(sender: AnyObject) {
}
#IBAction func resetButton(sender: AnyObject) {
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Here is the output console:
2015-07-23 12:52:26.877 Stop Watch[7472:467329] *** Terminating app
due to uncaught exception 'NSUnknownKeyException', reason:
'[<Stop_Watch.ViewController 0x7ffdf1435b60> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key play.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010a814c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010c37fbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010a8148a9 -[NSException raise] + 9
3 Foundation 0x000000010ac32b53 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x000000010a75cd50 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x000000010b38b4eb -[UINib instantiateWithOwner:options:] + 1506
6 UIKit 0x000000010b1e36d8 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7 UIKit 0x000000010b1e3cc8 -[UIViewController loadView] + 109
8 UIKit 0x000000010b1e3f39 -[UIViewController loadViewIfRequired] + 75
9 UIKit 0x000000010b1e43ce -[UIViewController view] + 27
10 UIKit 0x000000010b0ff289 -[UIWindow addRootViewControllerViewIfPossible] + 58
11 UIKit 0x000000010b0ff64f -[UIWindow _setHidden:forced:] + 247
12 UIKit 0x000000010b10bde1 -[UIWindow makeKeyAndVisible] + 42
13 UIKit 0x000000010b0af417 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2732
14 UIKit 0x000000010b0b219e -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
15 UIKit 0x000000010b0b1095 -[UIApplication workspaceDidEndTransaction:] + 179
16 FrontBoardServices 0x000000010de7c5e5 __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 21
17 CoreFoundation 0x000000010a74841c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18 CoreFoundation 0x000000010a73e165 __CFRunLoopDoBlocks + 341
19 CoreFoundation 0x000000010a73df25 __CFRunLoopRun + 2389
20 CoreFoundation 0x000000010a73d366 CFRunLoopRunSpecific + 470
21 UIKit 0x000000010b0b0b02 -[UIApplication _run] + 413
22 UIKit 0x000000010b0b38c0 UIApplicationMain + 1282
23 Stop Watch 0x000000010a618fa7 main + 135
24 libdyld.dylib 0x000000010cab5145 start + 1
25 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
After looking at the console log, I am pretty sure the crash occurs because of a missing outlet connection.
Press Cmd+Shift+F and type 'play' in the search field.
Look for a entry in your storyboard file, of the form ...: Outlet = "play".
Click on that entry and remove it by clicking on the 'x' button next to play.
This should fix the crash.
Whenever you see an error of the form:
... this class is not key value coding-compliant for the key ...
you should check if there is a missing outlet in your storyboard or xib.

StopWatch app keeps crashing

SO I'm making a simple stopwatch app via a tutorial I found online. I followed the code word for ford and created a the UI to connect to it too.
However, whenever I try to run the program it the iOS Simulator fails to get past the screen which states the name of the app. Then it produces a ton of code, and highlights this:
class AppDelegate: UIResponder, UIApplicationDelegate {`
under which it states THREAD 1: signal SIGABRT
What does that mean?
Also in the console I get this message:
(apologies in advance for the big chunk of code, tabbing it it didn't seem to work)
2015-06-15 15:53:54.313 stopwatch2[20524:1296474] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<stopwatch2.ViewController 0x7f9280476960> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key display.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010fcecc65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000111857bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010fcec8a9 -[NSException raise] + 9
3 Foundation 0x000000011010ab53 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x000000010fc34d50 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x000000011086352b -[UINib instantiateWithOwner:options:] + 1506
6 UIKit 0x00000001106bb718 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7 UIKit 0x00000001106bbd08 -[UIViewController loadView] + 109
8 UIKit 0x00000001106bbf79 -[UIViewController loadViewIfRequired] + 75
9 UIKit 0x00000001106bc40e -[UIViewController view] + 27
10 UIKit 0x00000001105d72c9 -[UIWindow addRootViewControllerViewIfPossible] + 58
11 UIKit 0x00000001105d768f -[UIWindow _setHidden:forced:] + 247
12 UIKit 0x00000001105e3e21 -[UIWindow makeKeyAndVisible] + 42
13 UIKit 0x0000000110587457 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2732
14 UIKit 0x000000011058a1de -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
15 UIKit 0x00000001105890d5 -[UIApplication workspaceDidEndTransaction:] + 179
16 FrontBoardServices 0x00000001133675e5 __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 21
17 CoreFoundation 0x000000010fc2041c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18 CoreFoundation 0x000000010fc16165 __CFRunLoopDoBlocks + 341
19 CoreFoundation 0x000000010fc15f25 __CFRunLoopRun + 2389
20 CoreFoundation 0x000000010fc15366 CFRunLoopRunSpecific + 470
21 UIKit 0x0000000110588b42 -[UIApplication _run] + 413
22 UIKit 0x000000011058b900 UIApplicationMain + 1282
23 stopwatch2 0x000000010faf0ff7 main + 135
24 libdyld.dylib 0x0000000111faf145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
However, this is my actual code:
import UIKit
class ViewController: UIViewController {
var timer = NSTimer()
var count = 0
func updateTime() {
count++
time.text = "\(count)"
}
#IBOutlet var time: UILabel!
#IBAction func pause(sender: AnyObject) {
timer.invalidate()
}
#IBAction func stop(sender: AnyObject) {
timer.invalidate()
count = 0
time.text = "0"
}
#IBAction func start(sender: AnyObject) {
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("updateTime"),userInfo: nil, repeats: true)
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Someone please help?
You probably connected an object called display to your View Controller, but then removed/changed the property in the source code.
You have to go to your controller in the Storyboard, click the outlets icon and delete the display outlet, it will have an exclamation mark.

Don't know why my app is crashing [duplicate]

This question already has answers here:
setValue:forUndefinedKey: this class is not key value coding-compliant for the key [duplicate]
(20 answers)
Closed 7 years ago.
I am very new to swift, extremely new, and I will probably feel like an idiot for asking this question. My very simple goal is that when my button is tapped the button's title will disappear, but unfortunately the app is crashing every time I run it and I don't know what I'm doing wrong. Thank you for the help.
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var background1: UIImageView!
#IBOutlet weak var screenButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.screenButton.setTitle("Tap!", forState: UIControlState.Normal)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func screenTapped(sender: AnyObject) {
self.screenButton.setTitle("", forState: UIControlState.Normal)
}
}
2015-04-10 17:13:41.465 TopScore[6391:414281] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key screenTapped.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000104fc0a75 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000106b18bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000104fc06b9 -[NSException raise] + 9
3 Foundation 0x00000001053dbd43 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x0000000104f0a5e0 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x0000000105b1a4ed -[UINib instantiateWithOwner:options:] + 1506
6 UIKit 0x0000000105978a88 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7 UIKit 0x0000000105979078 -[UIViewController loadView] + 109
8 UIKit 0x00000001059792e9 -[UIViewController loadViewIfRequired] + 75
9 UIKit 0x000000010597977e -[UIViewController view] + 27
10 UIKit 0x0000000105898509 -[UIWindow addRootViewControllerViewIfPossible] + 58
11 UIKit 0x00000001058988a1 -[UIWindow _setHidden:forced:] + 247
12 UIKit 0x00000001058a4f8c -[UIWindow makeKeyAndVisible] + 42
13 UIKit 0x000000010584f0c2 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2732
14 UIKit 0x0000000105851e3e -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
15 UIKit 0x0000000105850d35 -[UIApplication workspaceDidEndTransaction:] + 179
16 FrontBoardServices 0x00000001086ca243 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
17 CoreFoundation 0x0000000104ef5c7c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18 CoreFoundation 0x0000000104eeb9c5 __CFRunLoopDoBlocks + 341
19 CoreFoundation 0x0000000104eeb785 __CFRunLoopRun + 2389
20 CoreFoundation 0x0000000104eeabc6 CFRunLoopRunSpecific + 470
21 UIKit 0x00000001058507a2 -[UIApplication _run] + 413
22 UIKit 0x0000000105853580 UIApplicationMain + 1282
23 TopScore 0x0000000104de1cee top_level_code + 78
24 TopScore 0x0000000104de1d2a main + 42
25 libdyld.dylib 0x00000001072f4145 start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
At some point, you accidentally set up an outlet called screenTapped. You need to find that outlet in Interface Builder in your storyboard and delete it.
What you want is an action from the button to screenTapped:. An action and an outlet are two very different things.

Resources