How to fix "this class is not key value coding-compliant" after accidentally adding an IBOutlet instead of an IBAction

It has happened to us all: you’re in a storyboard, you’re using the Assistant Editor, you want to control-drag from a button into your code and create an action.

But sadly you forget to select “Action” from the drop down menu and instead create an outlet.

No biggie you think, deleting the outlet code. You go back and create the action properly, run the app… and get an error message such as this one:


*** Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key badAction.’

Yikes! Unless you’re using Version Control, there is no way to undo adding that bad outlet. So you ask yourself: Will I have to start from scratch, or is there a way to fix your app?

Yes this is fixable – all we need to do is examine our storyboard file in Source Code mode, then find the problem and eliminate it. Here’s how you do it:

This content is for members only.

Once you’re done, run the app again and all should be fine.

To display the storyboard in the visual editor again, just control-click the file file again, and select “Open as – Interface Builder, iOS Storyboard”.





7 thoughts on “How to fix "this class is not key value coding-compliant" after accidentally adding an IBOutlet instead of an IBAction

  1. Ho do i fix it if i have not a outlet’s name? my error like this:
    ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key .’

    1. Hi Dajrone, it’s difficult to diagnose without seeing more of your code. One of the reasons this can happen is when you set a property on an instance that doesn’t have it; for example, say you’ve written a subclass with a property, but you’re accidentally instantiating its parent class and try to set that property. To hunt down where the problem happens, set an exception breakpoint and see where Xcode stops your code.

  2. Hello Versluis,

    i am using storyboard and when i tap on the profile button my app crashes only on 4s device.
    even not crashes in the simulator. how to fix i am not getting please help.your any suggestion would be highly appreciated.Thanks

    here is my code :
    – (IBAction)profileButtonTapped:(id)sender
    {
    HomeViewController *homeView = [self.storyboard instantiateViewControllerWithIdentifier:@”gotoProfileVC”];
    [self presentViewController:homeView animated:YES completion:nil];
    }

    here is crash log:

    Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.’

  3. please ignore the previous crash log:

    Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.’

    1. Hi Yash, those things are tricky to find. It may be something in your storyboard rather than your code. Have you tried setting an exception breakpoint? Those will sometimes stop your app at the line of code that’s upsetting Xcode. That’s all I can suggest.

Leave a Reply