Why does xcode crash so much




















App crashes are a natural part of the development cycle. The challenge is to understand the real reason behind the crash and apply the proper fix, not just hide the crash. Download the starter project for this tutorial by using the Download Materials button at the top or bottom of this page. The project shows some common scenarios that cause your app to crash. But before you start looking at crashes and their causes, take a moment to review three important tools to help you track down crashes when they happen.

Pinpointing the cause of a crash can be tricky. Luckily, there are some helpful tools that make this job much easier. Your first step in this tutorial is to get to know three of the most important.

To create a breakpoint on any line, simply click on the line number in your source file where you want the execution to stop. Whenever an app that ran from Xcode crashes, the debugger shows you the line that crashed. The exception breakpoint automatically stops the app when a crash happens and shows you the line that caused it. Choose Exception Breakpoint… from resulting menu. Click anywhere outside the resulting dialog to set the breakpoint.

The Console Log is at the bottom of the Xcode window. It could highlight something that can help you make your app better. The third valuable tool for investigating crashes is the Variables View.

The view will only show the values of the variables in the current scope when your execution pauses, which goes hand-in-hand with breakpoints.

The Console Log also shows the values of variables, but the Variables View is more visual and shows you all the variables instead of just one. Console Log printing the value of a variable that is also present in the Variables View. Variables View can show more than just text information. It can show the visual content of a UI element. Now that you know the tools you need to fix this broken app, build and run the starter app and take a look at the first exhibit.

Swift introduced optionals , which mean an object or an expression may have a value, or it may not. This is the most common reason for your app to crash. Build and run the app, then open the first item — titled Force Unwrapping — in the gallery screen. The sum of the numbers will appear on the screen when you tap the Calculate button.

Give it a shot. Great, so it works as you intended. Now, play around with it and add ,two at the end of the numbers sequence:. The crash is in ForceUnwrappingViewController. The Console Log has information on the crash and the Variables View shows the values of item and finalValue within the scope of calculateSum items:. The value of item is "two" , so when you converted it to an Int it failed, giving a nil value. The force unwrapping by the! The po command you entered before the expression stands for print object , which is an LLDB command to print the description of an object.

You can also use p , but the result in the console will look slightly different. So Int item is nil , and when you execute po Int item! Add a breakpoint on the same line that caused the crash and restart the app. Remember to write ,two before you calculate the sum. The value of item on the breakpoint is 4 and the result of Int item gives a value instead of nil.

In other words, it works when the value is a string with numeric digits, but not with alphabetical letters, even when they form the name of the number.

Disable the breakpoint by clicking on the blue arrow and it will become semi-transparent blue. Build and run and add any kind of text you want in the text field after the numbers. Instead of adding the numbers, delete the last one and try again. For those who are still struggling: Add a possible restart to your steps. After trying the above multiple times, adding the restart after made the difference.

This site uses Akismet to reduce spam. Learn how your comment data is processed. The one where you can enter a comment that nobody at Apple will ever read or respond to: This is a peculiarity that can happen with a particular project. Looks like that project has a problem. How to fix this To fix this problem: open a Finder window and navigate to your project right-click on the.

Until this problem happens again. Removing the 3 occurrences of these lines in the project. There have been many solutions proposed over the years for this kind of bizarre Xcode behavior, so I have included all those steps as well; however, I have added a few of my own that when done together and in order have never failed to resolve every weird Xcode issue that I have come across. I realize that some of them at first glance seem like overkill or like they should not matter, but my experience has shown that each step plays a part in getting Xcode back into proper working order.

Therefore, I do NOT recommend skipping any steps or changing their order. With that said, if you discover the need to tweak the steps below, please do post a comment. Xcode does change constantly so these steps may also need change as well over time. I assume your actual background task is [self initBackground]; , otherwise you should put it outside the block and before endBackgroundTask call. Also, I noticed your pauseDownloads code now, it seems you are performing downloads using NSOperationQueue when app goes in background.

In such a case, ensure that the endBackgroundTask is not called until you have finished downloading or expiration handler is executed. In other words, the control doesn't return too early which means you might need to monitor these download NSOperation s. Asked 4 Months ago Answers: 5 Viewed 99 times. I've run the app on a device outside of Xcode, and it seems to work perfectly fine. Still can't find where command line tools is kept though. Still crashes.

Thing is I had no issues until the most recent Xcode update. Could it be an Xcode bug? Could that be interfering? Edit: It's caused by a race condition in the debug server I hear.



0コメント

  • 1000 / 1000