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:
The same menu allows you to toggle syntax formatting for the selected file:
None: Turns syntax formatting off for the file.
Default for file type: Turns syntax formatting on for the file, using your global syntax formatting settings (see “Configuring Syntax Formatting”).
To specify whether Xcode applies syntax formatting to all files that you open, use:
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:
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.”
Last updated: 2008-02-08