-
Notifications
You must be signed in to change notification settings - Fork 472
Common Issues
Charlie Hieger edited this page Oct 16, 2015
·
23 revisions
While learning to develop in iOS, you will undoubtedly encounter many issues. Fortunately, many of these issues are caused by a handful of very common issues. Awareness of these common pitfalls along with knowledge of how to investigate clues given to us by Xcode, will help to get us out of trouble when we have errors or crashes.
There are two main categories of errors, Compiler Errors and Run-Time Errors.
- Symptoms: You have little red stop signs in your file margins. As a result, Your app fails to build.
- Diagnose: Click on the red stop signs to get hints on what and where the issue is.
- Symptoms: Your app builds fine, but at a certain point it "crashes".
-
Diagnose: Go to the Debug area pane at the bottom of Xcode.
- 1: The Console, (bottom right window), will likely have a long list of confusing "computer talk", fortunately, the useful information is found in the first paragraph all the way at the top, so get scrolling!
- 2: The second place to look is in the Variables View to the left of the console.
- Translation: This basically means that sometime while your app was running, it was looking for something and instead got nothing, nil.
- Common Cause An outlet was created but got disconnected.
-
Diagnose:
- Step 1: We find our first clue is in the console. It tells us that something has no (nil) value. s
-
Step 2: We check the Variables Window next. When we expand the self heading, we see that, pigImageView = (UIImageView!) nil, "nil" being the keyword. This means
pigImageView
has no value, and Xcode is telling us that it should. - Step 3: We go to the swift file where that variable is declared. We notice that the little circle to the left where we make connections is empty. AH HA! Our code was trying to do something with the pigImageView, but it was not connected to the actual imageView in the Storyboard.
- Solution: Reconnect by dragging from the empty circle to our pig imageView in Storyboard.
- Translation: Basically, there is a connection somewhere behind the scene that is looking for a specific outlet but is not finding it.
- Common Cause: The name of an outlet was changed or deleted but the connection is still there.
-
Diagnose:
-
Step 1: Scroll all the way to the top of the Console to find the useful information.
- The ViewController where the error is occurring.
- The Key Value Coding-compliant tells you there is a connections issue.
- the name after for the key is what you will be looking for when you investigate connections.
- Step 2: Select the offending ViewController by clicking on the yellow dot. Open the Utilities pane and select the Connections Inspector.
- Solution: Delete the bad connection by clicking the little "x" between the connections. The bad connection should have an "!" on the right side instead of a little circle.
-
Step 1: Scroll all the way to the top of the Console to find the useful information.