After you create a swift project in Xcode and write some swift source code, you must want to debug your iOS app to help you to find out and fix errors exist in your app. Debug and find error messages in Xcode is very easy, this article will tell you how to do it.
1. How To Set BreakPoint In Xcode.
- Open your Xcode project, then edit your swift source code file ViewController.swift by click it.
- If you want to add a breakpoint, just click the beginning of the source code line. When you see there is a blue arrow at the beginning of the swift source code line, this means the breakpoint has been added.
- You can right click the breakpoint to popup a breakpoint manager menu list, you can do a lot of operations ( such as edit, disable, delete and reveal ) to this breakpoint by these menu items.
- When you click the Edit Breakpoint… menu item, it will popup another dialog which will let you to set breakpoint condition ( the breakpoint take effect only when this condition is matched ) or add breakpoint action ( the action can be a shell command etc. ).
- When you click the Disable Breakpoint menu item, the breakpoint will be disabled, and the source code execution will not stop at the breakpoint, and the breakpoint arrow’s color change to light blue also.
- When you click the Delete Breakpoint menu item, the breakpoint will be removed.
2. How To Start Debug Source Code In Xcode.
Just click the triangle Build and then run the current schema button at xcode top left ( ) to start the iOS app as normal, when the code execution run to the breakpoint, it will stop there, and then you can debug the swift source code such as watch variable values etc.
3. How To Find Out iOS App Execution Error Messages In Xcode.
If you find your iOS app do not act as what you want, maybe there are some exceptions that has been thrown. But you should get the exception message to analyze the error reason. You can find the error messages follow below steps.
- Click View —> Debug Area —> Activate Console menu item to show the activate console window at the bottom of xcode.
- If you can not see the activate console window, you can click the View —> Debug Area —> Show Debug Area sub menu item in above menu list, then you can see below debug area window, you can get the error messages in the right activate console window panel.