How to fix iOS Swift XCODE NSUnknownKeyException

The NSUnknownKeyException is most likely caused by a broken outlet in your view controller. You can identify the screen throwing this error using the log. The [project_name].[view_controller_name] gives the view controller and the outlet name is given which is ‘tipControl’ in the above example. To fix this error follow the following steps:

STEP 1: Go to the storyboard containing the broken outlet here it is main.storyboard

STEP 2: Open the “Connections Inspector” tab on the right

If you try running the app at this point you will get the following error. This is because we missed a crucial step in fixing the original error. You can see in the debug session that the value for “myTipControl” is nil.

STEP 3: Open the storyboard again and drag and connect the nil outlet to the right UI element in the storyboard as shown:

Empty outlet marked by an unfilled circle

STEP 4: Run the app again and it works successfully.

Full Stack Web Developer | Graduate student of MS in Computer Science at The University of Texas at Rio Grande Valley

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store