Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Formatting Code

Syntax formatting makes it easy to identify elements of your code by using different fonts and colors to identify particular elements, such as keywords and comments. For example, you can display comments in green and keywords in boldface.

Xcode supports syntax coloring for many programming languages; to see the languages that it supports, choose:

Xcode menu bar: View > Syntax Coloring

The same menu allows you to toggle syntax formatting for the selected file:

Configuring Syntax Formatting

To specify whether Xcode applies syntax formatting to all files that you open, use:

Xcode Preferences: Fonts & Colors > Use syntax-based formatting

When syntax formatting is active, Xcode uses element categories to determine what color to apply to particular elements in a file. An element category is a name that identifies a type of source-code element or text-editor user interface. Table 18-1 lists the element category Xcode uses:

Table 18-1  Syntax formatting element categories

Background

Numbers

Project Instance Variables and Globals

Selection

Keywords

Project Preprocessor Macros

Insertion Point

Preprocessor Statements

Other Class Names

Plain Text

URLs

Other Function and Method Names

Comments

Attributes

Other Constants

Documentation Comments

Project Class Names

Other Type Names

Documentation Comment Keywords

Project Function and Method Names

Other Instance Variables and Globals

Strings

Project Constants

Other Preprocessor Macros

Characters

Project Type Names

Using its knowledge of the syntax of a programming language, Xcode assigns keywords or textual constructs in a file, such as numbers or strings (text within quotation marks) to an element category to determine how it's formatted in the editor. In addition, you can tell Xcode to use a project’s Code Sense index to provide a richer store of symbol information to assign code fragments to element categories. That is, instead of only the current file, Xcode uses information about all the source files in the project to associate code fragments to categories.

Xcode provides several syntax formatting themes, which assign colors and fonts to all the element categories. You can also create your own themes.

For further details about configuring syntax formatting, see “Fonts & Colors Preferences.”



< Previous PageNext Page > Hide TOC


Last updated: 2008-02-08




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice