Documentation Archive


Xcode Overview

On This Page

Analyzing Your Code

Examining the Structure of Your Code with Code Folding

You can more easily focus your attention on a particular method or function in source code by hiding the other parts of the source code. Choose Editor > Code Folding > Fold Methods & Functions. Navigate to the method you want to unfold and double-click the Ellipsis button to unfold the method. The screenshot shows the configureConnectedGameControllers method unfolded.

image: ../art/CodeFolding.png

Move the pointer into the focus ribbon on the left edge of the editor to display a scope—such as the for statement in the screenshot—in a focus box. Additional scopes are indicated by degrees of shading in the code.

For more detail, see Folding and Unfolding Source Code.

Performing Static Code Analysis

Use the static analyzer to find bugs in your code before you even run your app. The static analyzer tries out thousands of possible code paths in a few seconds, reporting potential bugs that might have remained hidden or bugs that might be nearly impossible to replicate. This process also identifies areas in your code that don’t follow recommended API usage, such as Foundation, UIKit, and AppKit idioms.

To perform static code analysis, choose Product > Analyze. The Xcode static analyzer parses the project source code and identifies these types of problems:

  • Logic flaws, such as accessing uninitialized variables and dereferencing null pointers

  • Memory management flaws, such as leaking allocated memory

  • Dead store (unused variable) flaws

  • API usage flaws that result from not following the policies required by the frameworks and libraries the project is using

The static analyzer reports problems in the issue navigator, available by clicking the Issue Navigator button image: ../art/XC_O_navigator_issue_button_2x.png in the project navigator bar. Select an analyzer message in the issue navigator to display the associated code in the source editor. Click the corresponding message in the source editor. Use the pop-up menu in the analysis results bar above the source code editor to study the flow path of the flaw. Then edit the code to fix the flaw.

For more detail, see Performing Static Code Analysis in Xcode Help.