How to Fix the Most Common Xcode Errors

This article is a collection of the most common issues that I see the students of my course and audience members getting stuck on as well as how to fix them.

I thought writing up this reference will be handy to point people to in the future and I’ll continue to update it with new questions/issues that crop up from my students so please bookmark it!


ARTICLE CONTENTS

1. Xcode Simulator Errors
SpringBoard failed to launch application with error: 0
My iPhone simulator looks different?
My simulator screen is black when the app runs

2. App Runs And Then Crashes
Finding the error message after a crash
Unrecognized selector sent to instance
This class is not key value coding-compliant for the key…

3. Xcode Errors/App Won’t Run
Xcode complains that a method of some class doesn’t exist
Xcode warnings

4. My Xcode Interface Is Different
Missing panels or views
Can’t find UIElements in my Storyboard
Can’t drag UIElements onto my Storyboard


1. Xcode Simulator Errors


SpringBoard failed to launch application with error: 0

SpringBoard simulator error

If you get the error above when you try to run your application, the fix is really simple.
All you need to do is make sure your Simulator is the active window, and then open up the menu pictured below and click “Reset Content and Settings…”

simulator reset content and settings

It will ask you if you really want to reset and you should say yes.
Note that this will delete all the installed apps and settings on your iPhone simulator and reset it back to the original state.

Now when you run your app from Xcode again, you won’t get that error.


My iPhone simulator looks different?

If your iPhone simulator doesn’t look like the one you see me using in my videos, it’s because your iOS simulator is at a different zoom level.

The frame or bezel on the simulator also differs from level to level so if you don’t see an iPhone bezel on your simulator, try changing your zoom level as shown in the screenshot below.

ios simulator zoom level

You can also hit command + 1-3 on your keyboard as shortcut keys to control the zoom level of your simulator.


My simulator screen is black when the app runs

If you run your app and the iOS simulator is showing a black screen, I would first wait a little while. Sometimes it can take up to 15 seconds to launch your app initially.

Secondly, I would reset the simulator like I mentioned above and try to run my app again.

If that still doesn’t work, then maybe you have accidentally set some breakpoints which is stopping the app execution.

Run your app, then bring Xcode to the foreground and see if you see something like the below with a green line (representing where execution has halted) stopped at a blue marker (which is a breakpoint):

xcode breakpoint simulator black screen

If you see something like the above screenshot, that means that you’re seeing a black screen because the app execution has stopped. All you need to do is to either remove the breakpoint by clicking the blue marker and dragging it off the gutter (and then re-run your app).

Or you can disable all breakpoints by this menu command in Xcode:
Xcode deactivate breakpoints

I see this happening a lot for beginners who aren’t aware of what breakpoints are.

Breakpoints are used to halt execution at a certain point so that you can inspect variables and peek into your objects to debug.

You can set breakpoints by clicking the gutter beside a line of code and it’ll add a little blue marker there. So you can see why beginners may accidentally have set breakpoints and not realize it when they run their app!

2. App Runs And Then Crashes


Finding the error message after a crash

When your app runs and then crashes (whether it crashes as soon as your run it or it crashes after you click something), you need to know where to find the error message so that you can see what’s wrong.

After the crash, go to Xcode in the lower right hand pane, scroll all the way to the top.
error message in debug console


Unrecognized selector sent to instance error

unrecognized selector sent to instance

So now that you know how to find the actual error message when your app crashes, the next step is to learn to recognize some of the more common types of messages because they will hint at what’s wrong.

The unrecognized selector error means that somewhere, a method was called on an object and that object didn’t have that method so it crashes. “Selector” is another term for a method.

As you can see in the error message above, it tells you the method that was called was “showDieNumber” and the object that it was called on was a UIView object.

So now you can go back to your code and see where you’re calling the “showDieNumber” method and why the object doesn’t have that method.

Check if that method exists in the header (.h) file of the class and pay attention to the parameters and letter casing to make sure it matches.

If you’re calling a method on a IBOutlet property that is referring to an element in your storyboard, then make sure that the UIElement has it’s custom class set to the class that has the “showDieNumber” method.

setting custom class in storyboard


This class is not key value coding-compliant for the key

If you’re using Storyboards to build your user interface and you encounter a detailed error similar to this:

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

The actual name of the key (in this case “handleButtonClick” may be different for you), but this error may indicate that there’s a UIElement in your Storyboard that’s connected to a property which doesn’t exist anymore. This can occur if you connected the UIElement to a property and then removed the property from the .H file.

In order to fix it, go into your storyboard and right click each element to check the connections to the properties and “break” any connections to properties that don’t exist in your .H file anymore by clicking the little “x” beside each bad connection.

3. Xcode Errors/App Won’t Run


Xcode complains that a method of some class doesn’t exist

If you run your app and you get some build errors, that means Xcode has detected that the syntax of your code is wrong.

If Xcode is complaining about a specific identifier doesn’t exist, or the “@end” tag is missing, then check that all of your opening curly braces have corresponding closing curly braces.

If you look at the two screenshots below, both build errors are caused because of missing curly braces. Can you spot the missing curly brace?

missing closing curly brace
missing closing curly brace


Xcode warnings

Xcode warnings are highlighted in yellow and they won’t stop you from running your app but it’s a good practice to reduce the number of them.

I’ll be illustrating some of the more common ones in the future in this section.

4. My Xcode Interface Is Different


Missing panels or views

If you’re missing some panes in your Xcode interface, you can check the buttons in the upper right corner. They’re used to toggle the main panels.

toggle xcode panels and views

In the debug/console area, there are also a couple of buttons to toggle the panes in the debug area:
toggle debug views

If you’re in Storyboard designer view, there’s a button that many people miss. This button controls the document outline which lists the UI Elements in your storyboard in a tree hierarchy view.

toggle storyboard document outline


Can’t find UIElements in my Storyboard

If you don’t see the UI elements list in your storyboard view then your library pane may be on the wrong tab. See the screenshot below:

uielement library tabs


Can’t drag UIElements onto my Storyboard

If you drag UI elements onto your storyboard and you can’t add any to your view, then you may be in zoomed out view. When you’re zoomed out in your storyboard, you can’t add any elements into the view. The zoomed out view gives you and overview of your views and allows you to position your controllers on the storyboard.

To get back into zoomed in view, just double click on an empty area on your storyboard and you’ll zoom back in and be able to drag elements onto your views.

54 Shares
Share32
Tweet10
+14
Share8
Pin