Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialboris said
3,607 PointsError in app delegate.swift
So when I run my app it crashes and there is an error in app delegate.swift. This has happened to all my other apps I have tried to make recently. Here is the error code:
2016-03-01 06:15:01.986 Algorhythm[48318:4052082] Unknown class PlayMasterViewController in Interface Builder file. 2016-03-01 06:15:01.999 Algorhythm[48318:4052082] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fba20510540> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key aButton.' *** First throw call stack: ( 0 CoreFoundation 0x000000010376ee65 exceptionPreprocess + 165 1 libobjc.A.dylib 0x00000001054aedeb objc_exception_throw + 48 2 CoreFoundation 0x000000010376eaa9 -[NSException raise] + 9 3 Foundation 0x0000000103b379bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288 4 UIKit 0x000000010411a320 -[UIViewController setValue:forKey:] + 88 5 UIKit 0x0000000104348f41 -[UIRuntimeOutletConnection connect] + 109 6 CoreFoundation 0x00000001036af4a0 -[NSArray makeObjectsPerformSelector:] + 224 7 UIKit 0x0000000104347924 -[UINib instantiateWithOwner:options:] + 1864 8 UIKit 0x0000000104120eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381 9 UIKit 0x0000000104121816 -[UIViewController loadView] + 178 10 UIKit 0x0000000104121b74 -[UIViewController loadViewIfRequired] + 138 11 UIKit 0x00000001041222e7 -[UIViewController view] + 27 12 UIKit 0x0000000103ff8ab0 -[UIWindow addRootViewControllerViewIfPossible] + 61 13 UIKit 0x0000000103ff9199 -[UIWindow _setHidden:forced:] + 282 14 UIKit 0x000000010400ac2e -[UIWindow makeKeyAndVisible] + 42 15 UIKit 0x0000000103f83663 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131 16 UIKit 0x0000000103f89cc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760 17 UIKit 0x0000000103f86e7b -[UIApplication workspaceDidEndTransaction:] + 188 18 FrontBoardServices 0x0000000107343754 -[FBSSerialQueue _performNext] + 192 19 FrontBoardServices 0x0000000107343ac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45 20 CoreFoundation 0x000000010369aa31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 21 CoreFoundation 0x000000010369095c __CFRunLoopDoSources0 + 556 22 CoreFoundation 0x000000010368fe13 __CFRunLoopRun + 867 23 CoreFoundation 0x000000010368f828 CFRunLoopRunSpecific + 488 24 UIKit 0x0000000103f867cd -[UIApplication _run] + 402 25 UIKit 0x0000000103f8b610 UIApplicationMain + 171 26 Algorhythm 0x000000010358f45d main + 109 27 libdyld.dylib 0x0000000105fb792d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
4 Answers
boris said
3,607 Pointsimport UIKit
class PlaylistMasterViewController: UIViewController {
@IBOutlet weak var aButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
aButton.setTitle("Press Me!", forState: .Normal)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
boris said
3,607 Pointsimport UIKit
class PlaylistMasterViewController: UIViewController {
@IBOutlet weak var aButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
aButton.setTitle("Press Me!", forState: .Normal)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
boris said
3,607 Pointsimport UIKit
class PlaylistMasterViewController: UIViewController {
@IBOutlet weak var aButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
aButton.setTitle("Press Me!", forState: .Normal)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Chris Wolchesky
12,025 PointsYour class names aren't matching across files. According to the original error text it's looking for "PlayMasterViewController", but the code you posted is for "PlaylistMasterViewController".
2016-03-01 06:15:01.986 Algorhythm[48318:4052082] Unknown class PlayMasterViewController in Interface Builder file.
class PlaylistMasterViewController: UIViewController {
//...
}
Chris Wolchesky
12,025 PointsChris Wolchesky
12,025 PointsCan you post the source code for the associated error? Judging on the error text:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key aButton.'
I would guess that you're referencing a key on an object which does not have the associated key, but having the context of it's use would be helpful.