191
votes

I'm programming an app in swift and when I run the test app on the iPhone simulator everything works, but then I try to swipe right, which is a gesture that I added for it to go to the next Page(View Controller Two) it crashes and shows this error report in the console log.

2014-10-18 12:07:34.400 soundtest[17081:818922] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<soundtest.ViewControllerTwo 0x7f92f1f20090> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key sfdfa.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001067813f5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001082afbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000106781039 -[NSException raise] + 9
    3   Foundation                          0x0000000106b984d3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
    4   CoreFoundation                      0x00000001066cb400 -[NSArray makeObjectsPerformSelector:] + 224
    5   UIKit                               0x00000001072ce97d -[UINib instantiateWithOwner:options:] + 1506
    6   UIKit                               0x000000010712f698 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
    7   UIKit                               0x000000010712fc88 -[UIViewController loadView] + 109
    8   UIKit                               0x000000010712fef9 -[UIViewController loadViewIfRequired] + 75
    9   UIKit                               0x000000010713038e -[UIViewController view] + 27
    10  UIKit                               0x00000001076cd83f -[_UIFullscreenPresentationController _setPresentedViewController:] + 65
    11  UIKit                               0x000000010710bc49 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 105
    12  UIKit                               0x000000010713c121 -[UIViewController _presentViewController:withAnimationController:completion:] + 1746
    13  UIKit                               0x000000010713e461 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 132
    14  UIKit                               0x000000010713e385 -[UIViewController presentViewController:animated:completion:] + 229
    15  UIKit                               0x00000001073bb9d6 _UIGestureRecognizerSendActions + 262
    16  UIKit                               0x00000001073ba679 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 532
    17  UIKit                               0x00000001073bf296 ___UIGestureRecognizerUpdate_block_invoke662 + 51
    18  UIKit                               0x00000001073bf192 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 254
    19  UIKit                               0x00000001073b520d _UIGestureRecognizerUpdate + 2796
    20  UIKit                               0x00000001070520a6 -[UIWindow _sendGesturesForEvent:] + 1041
    21  UIKit                               0x0000000107052cd3 -[UIWindow sendEvent:] + 667
    22  UIKit                               0x000000010701fae1 -[UIApplication sendEvent:] + 246
    23  UIKit                               0x000000010702cbad _UIApplicationHandleEventFromQueueEvent + 17370
    24  UIKit                               0x0000000107008233 _UIApplicationHandleEventQueue + 1961
    25  CoreFoundation                      0x00000001066b6ad1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    26  CoreFoundation                      0x00000001066ac99d __CFRunLoopDoSources0 + 269
    27  CoreFoundation                      0x00000001066abfd4 __CFRunLoopRun + 868
    28  CoreFoundation                      0x00000001066aba06 CFRunLoopRunSpecific + 470
    29  GraphicsServices                    0x000000010a1699f0 GSEventRunModal + 161
    30  UIKit                               0x000000010700b550 UIApplicationMain + 1282
    31  soundtest                           0x000000010624503e top_level_code + 78
    32  soundtest                           0x000000010624507a main + 42
    33  libdyld.dylib                       0x000000010ae4a145 start + 1
    34  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
30
It's most likely that you've wired up something in a NIB that no longer exists. It looks like the crash is when the view you're trying to transition to is getting loaded. I would check all of the outlets in the inspector pane (on the right) and make sure they're present? This could also happen if you've wired up a button to an IBAction that doesn't exist anymore (or has been renamed)cmyr
There is nothing that isn't being used and its still giving me the error.Nick
If you are using Xcode 8 with Swift 2.3 legacy mode then see this answer: stackoverflow.com/a/39548326/5175709Honey
In general, always go to console, hit cmmd + F so you can search inside console and search for Terminating app due to uncaught exception, exactly 1 line after that you will see reason: which tells you the reason your app has crashed. (yeah I've had this error too many times :)Honey
It could also be helpful to create Exception Breakpoint in Debug->Breakpoints. Debugger should then hopefully stop on the line of code where the problem is located.Chuck Boris

30 Answers

407
votes

CMYR - "his could also happen if you've wired up a button to an IBAction that doesn't exist anymore (or has been renamed)"

If you're running into this problem make sure that you go to Main.storyboard, RIGHT click on the yellow box icon (view controller) at the top of the phone outline and DELETE the outlet(s) with yellow flags.

What happens in instances like this is you probably named an action, then renamed it. You need to delete the old name and if that was the only issue will start right up in sim!

enter image description here

95
votes

Did you set the OS_ACTIVITY_MODE variable by any chance? To check if you have this variable set (and turn it off), in Xcode 9, do the following:

Select from Xcode menu Product -> Scheme -> Edit Scheme.. Select the Run scheme and look under Arguments. If you see the OS_ACTIVITY_MODE variable checked, deselect it

86
votes

In Xcode 9 and Swift 4:

Print exception stack to know the reason of the exception:

  1. Go to show break point navigator.
  2. Add (+) Add Exception Breakpoint.

  3. Select the new breakpoint, Control-Click, Edit Breakpoint.

  4. Add Action and Enter: po $arg1

enter image description here

8
votes

In my case, I was calling a delegate method but the method wasn't declared.

This error is generic and can appear by a number of reasons. Make sure you have not disabled your Logs to actually see what happened. Enable OS_ACTIVITY_MODE in the schemes if you have disabled it. You might have disabled it to prevent a lot of irrelevant logs but they are handy.

You can also trace the cause in more details by adding an exception breakpoint po $arg1. As already mentioned by Ahmed-Lotfi

Here is a common checklist that you can go through.

2) Check if you have renamed an IBOutlet and calling it
3) Check if you have renamed a method name or the method doesn't exist
4) Check if you are trying to add or remove any view from hierarchy
5) Check for any missing framework or library
6) Check if you’ve forgot to register your custom cell identifier
7) Check for any missing flag in the Proejct Setting (-obj) or any other linker flag etc.
7
votes

Other solutions didn't work form me, here's mine. It applies only to Xcode 8 when running in Swift 2.3 legacy mode:

Looks like Interface Builder is trying to rename the method that should be hooked up to the button.

Here's a radar with more details.

The solution (workaround) is to manually replace the method parameter name to _:

@IBAction func editPictureTapped(sender: UIButton) {  // not working
    print("Tapped")
}

Change to this:

@IBAction func editPictureTapped(_: UIButton) {     // working OK
    print("Tapped")
}
6
votes

It could also be wrong Segue Identifier Name. Eg -

performSegueWithIdentifier("wrongSegueName", sender: self)
4
votes

My situation was a little different, I was trying to segue into a UINavigationController, and what fixed it for me was getting the main queue portion.

For Objective-C:

dispatch_async(dispatch_get_main_queue(), ^{
    [self performSegueWithIdentifier:@"SegueName" sender:self];
});

For Swift 3:

DispatchQueue.main.async { [weak self] in
    self?.performSegue(withIdentifier: "SegueName", sender: self)
}
3
votes

This started to happen for me on Xcode 7, and I had no outlets with yellow flags that I could delete.

The only thing that worked for me was replacing this line in the AppDelegate:

[window addSubview:viewController.view];

to:

[window setRootViewController:viewController];
3
votes

For me, the problem was in my IBAction with a UIButton.

When you Ctrl+Drag to create an IBAction from a UIButton, make sure to select "UIButton" from the Type dropdown. The default selection of AnyObject causes the app to crash when you tap on the UIButton.

enter image description here

3
votes

It could also be a broken Triggered Segues, check in your storyboard, as soon as you reconnect the segues or outlet it all should work again.

Check the Segues

Make sure the Identifier of the Segue is correct and similar to your code.

enter image description here

2
votes

I ran into this issue when I changed the name of the variable which connected to one of my buttons. So keep that in mind!

2
votes

I'm new to Xcode, so it took me a few hours to figure out the issue in order to load xls file. I followed through most of the sample codes up there and none of them solves the error Xcode shown.

The solution I found was that we need to specify the 'Add to targets:' tick the project to add, when we import the xls file into Xcode by drag and drop into Project -> Supporting Files.

1
votes

there may be more than 1 IBAction for a button in your view controller try finding out those and removing all previous item for that button in your controller and create new button .It will solve your problem.

1
votes

Make sure you are not dynamically applying relative constraints to a view which is not yet there in view hierarchy.

UIView *bottomView = [[UIView alloc] initWithFrame:CGRectZero];
[self.view addSubview:bottomView];

bottomConstraint = [NSLayoutConstraint constraintWithItem:bottomView
                                                attribute:NSLayoutAttributeBottom
                                                relatedBy:NSLayoutRelationEqual
                                                   toItem:self.view
                                                attribute:NSLayoutAttributeBottom
                                               multiplier:1
                                                 constant:0];
bottomConstraint.active = YES;

In above example, bottomView has been made part of view hierarchy before applying relative constraints on it.

1
votes

I have got this error in the following 2 ways:

I was getting this error when I was pushing into another UIViewController.

HOWEVER by mistake I subclassed the other class from UITabBarController and was getting this error.

How I got it fixed? I subclassed from UIViewController and I was no longer crashing :)


I didn't want to use storyboard. So I deleted it. Yet I forget to delete its reference in the Project settings. I just clicked on the project >> General >> Deployment Info >> and I then I set the Main Interface to black space. (It was previously set to main)

As you can see for the both situations you're getting an error for accessing some object that does exist...

1
votes

I'm going to add my problem to the list of possible solutions in case anyone else happens upon this thread.

TableView cell identifier. First off make sure your cell has an identifier. Second, make sure you're referencing that identifier when you dequeue the cell.

1
votes

Swift 4:

I was getting this error because of a change in the UIVisualEffectView api. In Swift 3 it was ok to do this: myVisuallEffectView.addSubview(someSubview)

But in Swift 4 I had to change it to this: myVisualEffectView.contentView.addSubview(someSubview)

1
votes

I had this same error when I had a typo for one of the views while building constraints using the visual formatter. I hope that helps someone... or me again one day.

1
votes

If you're using react native and react-native-firebase, make sure you link up the Google-Services.plist file (https://github.com/invertase/react-native-firebase/issues/313#issuecomment-320435560)

1
votes

If some one came here after expo eject then below steps will help.

  1. Do, expo start in your terminal
  2. Go to iOS/ and install pod using pod install
  3. Run the build via Xcode.
0
votes

In my case, it was the UIAlertView on iPad: UIAlertController is Crashed (iPad). I didn't setup sourceView and sourceRect.

0
votes

For my case, Xcode 8.2.1, I had a Map Kit View in a view controller. So I went to

Build Phases > Link Binary With Libraries

and added MapKit.framework, then it was fine.

I think this will also apply to other views that require framework.

P.S. Running on iOS 9 told me that there was an issue about Map Kit View, while on iOS 10 told me nothing!

0
votes

Only the "drop armageddon" solution worked for me:

  • remove app from device
  • clean project
  • run new install on device
0
votes

In my case, it was XCode getting tired and failing to start app with this message, due to an assertion failing (that was set by our code).

Running on another device showed the assertion failure, which we were able to fix, and everything went back to normal.

0
votes

For Swift 2.3

This seems to be a bug with Xcode 8 and Swift 2.3, if you're connecting the button action to your code via storyboard be sure that Xcode didn't rename the action, for me it's adding a withSender: at the end of the methods, so what I do is going to my code and renaming the method to match the one Xcode wrote.

For any other version check the correct answer.

0
votes

In my case, it was InterfaceBuilder. I had copied some Views from another ViewController which messed up the constraints.

In InterfaceBuilder I had the red arrow error on the ViewController.

During execution the app crashed.

0
votes

In my case, the app crashed because I didn't set the storyboard's target membership.

0
votes

In my case the project Build Settings contained some to non-existing directories for Framework Search Paths and Library Search Paths.

0
votes

I had two issues:

1) My target didn't have the view controller included that was used in the storyboard file.

2) My storyboard was about 3 years old, I had to recreate one of the view controllers in the tab bar controller from scratch (it only had a UITextField and I still don't know why it wasn't working)

0
votes

Yet another possible cause:

In my case, I had a xib and was calling Bundle.main.loadNibNamed(... at which point it was crashing. All my IBOutlets and IBActions seemed fine. In the end I noticed that the nib was actually loading, but then when I tried to access the first (and only) view (nib.first), that was not working. In fact nib.count was returning a very large integer (max int?), instead of the expected 1. I tried re-adding the view, but still no luck.

In the end, I deleted the whole xib file and started again (but I kept some of the views in my clipboard so I can paste them instead of recreating them again).

This worked!