Editing Source Files

Much of the development process is actually spent writing source code. You spend a lot of time editing the files in your project, from authoring source code to modifying file characteristics, such as the file’s encoding. Xcode includes a full-featured editor that supports a number of features that make coding easier. For example, syntax coloring helps you distinguish the various code elements in a source file. Syntax-aware indenting makes it simple to generate readable, well-formatted source code by automatically indenting source code, and matching braces, as appropriate for the current context.

Xcode’s editor can display a great deal of information about the current file, such as line numbers, the location of breakpoints and build errors, and more. It supports a number of quick-access features, such as the ability to jump to any symbol definition or declaration in a file, jump between header and implementation files, and look up documentation for a symbol. In this way, you can quickly move around within or between files and find the information you need.

Using the symbol information available through Code Sense, Xcode’s editor also supports code completion. As you type in a source code file, code completion suggests symbols appropriate for the current context. You can have Xcode automatically insert the symbol name and prototype, instead of typing all of the information yourself.

Xcode gives you many ways to open files and access information in an Xcode editor. You can choose to have the editor open as a standalone window, or you can use the attached editor to open files directly in the project, Build Results, Project Find, or Debugger windows.

Of course, many people are accustomed to the behavior of one particular text editor for authoring source code. They are extremely productive in this environment and prefer to keep using this editor, rather than learning the ins and outs of a new text editor. For this reason, Xcode also lets you specify an external program for opening and editing files in your project. In this way, you can manage project files and perform all other development tasks in Xcode while still opening and editing files in your usual editor. If you do decide to use Xcode’s editor, you can use Xcode’s built-in Metrowerks, BBEdit or MPW key binding sets for text editing operations to make your editing environment as familiar as possible.

The chapters that follow describe Xcode’s editor, show how to open and access files with Xcode’s editor or with an external editor, and show you how to take advantage of features such as code completion and syntax coloring to make the process of authoring source code easier and more efficient.