How to Get Started with Xcode Source Editor

The main tool you use to write code for an iPad application is the Xcode source editor, which appears as the Standard editor pane in the editor area on the right side of the Xcode Workspace window after you select a source code file in the Project navigator.

It also appears as the Assistant editor in a second pane if you click the Assistant Editor button — the middle Editor selector button in the top-right corner of the Workspace window.

Apple has gone out of its way to make the source editor as useful as possible by including the following:

  • Code completion: Code completion is a feature of the editor that shows symbols — arguments, placeholders, and suggested code — as you type statements. Code completion can be really useful, especially if you’re like me and forget exactly what the arguments are for a function.

    When code completion is active (as it is by default), Xcode uses the text you typed — as well as the context within which you typed it — to provide inline suggestions for completing what it thinks you’re going to type. You can accept inline suggestions by pressing Tab or Return.

    You can also see a pop-up list of suggestions by clicking an item in the suggestion list or clicking the up and down arrows to select an item. As you do so, the inline suggestion changes depending on what you selected. Press the Esc key, or Control+spacebar, to cancel a code completion operation.

    You can turn off code completion, or set options for code completion, by choosing Xcode→Preferences and clicking the Text Editing tab.

  • Automatic indenting, formatting, and closing braces: The source editor indents the text you type according to rules you can set in the Text Editing preferences pane. It also uses fonts and colors for the various syntax elements (variables, constants, comments, and so on) according to the settings in the Fonts & Colors pane of Xcode preferences.

    As for closing braces, anytime you type an opening brace ({) and then press Return, Xcode automatically adds a closing brace (}) — unless you’ve deactivated the Automatically Insert Closing “}” option in the Text Editing preferences.

  • Code folding in the Focus ribbon: With code folding, you can collapse code that you’re not working on and display only the code that requires your attention.

    You do this by clicking in the Focus ribbon column (see the figure) to the left of the code you want to hide (between the gutter, which displays line numbers and breakpoints, and the editor). A disclosure triangle appears, and clicking it hides or shows blocks of code.

    image0.jpg
  • Opening a file in a separate window: Double-click the file in the Project navigator to open the file in a new window.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.