Chapter 6. Editing Text

WHAT'S IN THIS CHAPTER?

  • Understanding editing windows and panes

  • Navigating text and jumping between files efficiently

  • Editing and reformatting text

  • Using syntax-aware display and completion features

  • Editing other types of files (Rich Text Format, property lists)

In the introduction, I mentioned that Xcode doesn't really do much of the actual development work. Most of the heavy lifting is performed by external tools — compilers, linkers, debuggers, and others — that are not part of the Xcode application, but Xcode does provide one critical tool that is integral to every developer's workflow: the text editor. You will spend far more time editing source files than doing almost any other single task. Learning how to edit efficiently and navigate your source files quickly will greatly enrich your productivity.

If you've spent any time at all using Mac OS X, you're familiar with the basic text editing concepts and commands. This chapter explores the powerful, and some obscure, extensions that Xcode adds to the core text editing facilities. It shows you a variety of techniques and shortcuts for navigating, editing, and reformatting text. Xcode also supplies a rich set of language-aware code formatting, coloring, and auto-completion features that make writing source code much more productive. Finally, this chapter touches on a number of ancillary topics like file encoding, localization, the spelling checker, and printing.

Xcode has, what seems like, a thousand features to aid your development, but this also means that there are a thousand features to learn — some of which are rather obscure. The more you learn about the ins and outs of the text editor, the more productive you'll be, but you can't learn them all in one sitting. Here's how I suggest you approach this chapter:

  • Skim this and the next chapter to get a general idea of what the Xcode editor has to offer.

  • Learn to use:

  • Once you become comfortable with those, return to this chapter to explore more advanced features.

WINDOWS AND PANES

Editing in Xcode occurs in an editor pane. An editor pane can be part of a multi-pane window, like the project window in the Default style, or it can be the sole content of a separate editor window. Figure 6-1 shows a file being edited in three panes: once in the project window, again in the editor pane of the project find window, and again in an independent editor window.

FIGURE 6-1

Figure 6-1. FIGURE 6-1

Editing Panes

Xcode editing panes are homogeneous. The features, functions, and capabilities are identical regardless of where they appear. This imparts one extremely useful feature: No matter where a source file appears in Xcode, you have the full power of the Xcode editor at your disposal.

The text of a file that appears in a search window, the debugger, or the object browser can all be edited immediately without any need to locate the file or open another window. The same file can appear in multiple editing panes at once. Changes made to one are reflected in all.

Opening a File in a Separate Window

To edit a file in a separate editor window, double-click the source file item in the project window. If the file already appears in an editing pane of another window, you can force it to open in a new window by choosing the Open in Separate Editor command. This command can be accessed from the File menu by holding down the Option key (Option+Command+O) or by Right/Control+clicking a source file in the project group. Selecting this command while an edit pane is active opens another window containing the same file.

Editor Panes in Multi-Pane Windows

The editor pane of a multi-pane window usually tracks some other selection in the window. For example, selecting a class in the class browser displays the source of the class's header in its editor pane. Clicking a line found in the Project Find window displays the file where the line was found in that window's editor pane, and so on.

The Project Window's Editor Pane

The editor pane of the project window is no exception, but the behavior is a little more complex. When you're using the Default and All-In-One Xcode styles, the project source list shares a window with the details list and an editor pane. Figure 6-2 shows all three panes visible at once.

FIGURE 6-2

Figure 6-2. FIGURE 6-2

Selecting a single file in either the Groups & Files list or the details list immediately brings the contents of that file into the editor pane — that is, if the editor pane is visible. As you saw in Chapter 3, the details list and the editor pane share the same area in the project window. You can adjust the division between the two by using the divider bar, the View

FIGURE 6-2

Note

The Editor toolbar button is shown in Figure 6-2, but is not part of the default project window toolbar. Choose View

FIGURE 6-2

All three configurations of the details list and editor pane are shown in Figure 6-3. On the left, only the details list is visible. On the right, only the editor pane is visible. In the center, both share the same area. The divider between them can be dragged to the top to fill the area with the editor pane, to the bottom to hide it, or anywhere in between. Double-clicking the divider alternately collapses the editor pane so it is completely hidden, or restores it to its previous location — which could be at the top, completely hiding the details list.

FIGURE 6-3

Figure 6-3. FIGURE 6-3

The View

FIGURE 6-3

Holding down the Option key turns the command into Zoom Editor In/Out Fully. When used in a multi-pane window like the project window, Zoom Editor In Fully collapses all other panes. This would be equivalent to expanding the editor, and then collapsing the Groups & Files list so only the editor pane is visible. Zoom Editor Out Fully runs the editor pane back down and re-expands the Groups & Files list. Using the All-In-One window style, this is a quick way of pushing everything else aside in order to see the code, and may be more convenient than opening the file in a separate window.

Normally, the division between the details list and the editor pane stays put until you change it. When the editor pane is collapsed, this requires two commands to edit the contents of a file. You must first select the file in a list, and then resize the divider or use the Zoom Editor In command before the editor pane is visible. If you find yourself doing this often, enable the Automatically Open/Close Attached Editor option in the General pane of the Xcode Preferences. Checking this option causes the editor pane to expand automatically whenever a single source file is selected in the Groups & Files or details list.

Using a Group Editor Window

Xcode, like most document-based applications, creates a new window for every file you open in a separate window. If that statement sounds ridiculously obvious, bear with me. It can, however, restrict all files to a single separate editing window. This mode is accessible only through the toolbar Grouped/Ungrouped control, shown in Figure 6-4.

FIGURE 6-4

Figure 6-4. FIGURE 6-4

If the control shows as Ungrouped, opening a new file in a separate editor creates a new window. There is no practical limit on the number of separate editor windows you can have open at a time. Clicking the button toggles the mode and establishes that window as the "group" editing window. In this mode, opening a file simply changes the file being displayed in the active pane of the group editor window; no new windows are created. This mode can be used to avoid window clutter. The setting of this mode does not affect any other windows that have already been created, and only one window can be designated as the group editor window at a time.

Opening Files from the Filesystem

Xcode also lets you open files in the traditional manner by picking a file in the filesystem. It will also respond to open document requests from the Finder or any other application. Xcode understands the formats of many file types that it doesn't "own." You can cause Xcode to open a file that would normally launch another application by dropping the file into Xcode's icon in the dock, as shown in Figure 6-5.

FIGURE 6-5

Figure 6-5. FIGURE 6-5

Opening an editable file using the traditional File

FIGURE 6-5

Open Quickly by Filename or Symbol

An extremely useful command for finding and opening a file is the File

Open Quickly by Filename or Symbol
FIGURE 6-6

Figure 6-6. FIGURE 6-6

Note

If you have text selected in the editor when you invoke the Open Quickly command, it's used as the default search. This makes it really easy to open a header file (select the #include filename, then press Command+Shift+D) or find the file that defines almost any symbol.

Closing and Saving Editor Panes

Close any window using the File

Closing and Saving Editor Panes

Because Xcode enables you to edit a source file in multiple windows simultaneously, there isn't a one-to-one correspondence between a window and a file. Unless you use the Close File "filename" command, closing a window does not necessarily force you to save the changes made to that file. Even closing all of the visible panes where a file was being edited might not force the changes to be written. The changes are held in memory until committed in response to another command. Files that have been modified but not yet saved appear grey in the project window. In Figure 6-7, the PromiseListViewController.h, PromiseListViewController.m, and DueDatePicker.h files have been edited but not saved.

FIGURE 6-7

Figure 6-7. FIGURE 6-7

The File

FIGURE 6-7
FIGURE 6-8

Figure 6-8. FIGURE 6-8

Some actions cause the Save All window to appear automatically. Closing a project forces you to save or abandon the changes made in all unsaved project files. You can configure the Build commands in the Xcode Preferences to automatically save all unsaved files or prompt you for which ones to save before building.

THE EDITOR PANE

It's now time to take a detailed look at the Xcode editor pane, shown in Figure 6-9.

The editor pane has a number of controls and features. In the center, naturally, is the editor with the content of the file being edited. Across the top edge is the navigation bar, the various functions of which are explained later in the "Navigating Within a File" section. Along the right edge are the scrollbars and split pane controls. On the left edge is the gutter and ribbon, explained later in the "Gutter" section. The line running down the right side of the main editing region is the page guide. Depending on your display preferences and the kind of file being edited, some of these features may not be visible. See the "Display Options" section to find out how to enable or disable them.

FIGURE 6-9

Figure 6-9. FIGURE 6-9

The active pane always has a blinking text cursor or a shaded text selection.

Note

You might get the idea that the text insertion cursor and the current text selection mentioned throughout this book are separate concepts. In reality, they are usually equivalent. The blinking text cursor is logically a text selection of zero characters. Both indicate the current location in the file. At times the behavior of a command is different when the selection is empty (when the text cursor is visible), but unless stated explicitly to the contrary, if you read one assume it applies equally to the other.

Scrollbars

The scrollbar controls are standard and shouldn't surprise anyone who has used a modern graphical user interface. Xcode enhances their basic behavior with a few extras.

Holding down the Option key when you click the arrow buttons scrolls the window slightly less than one screen's worth of text.

The editor is scroll-wheel aware, although a scroll-wheel is not an Xcode-specific feature. If your mouse, trackball, or trackpad has a scroll-wheel, the active editor pane will respond to it. I personally consider a multi-button trackball with a scroll-wheel an indispensable development tool.

The gutter, described in more detail later, indicates compiler errors and warnings for the text that is visible in the window. Warnings and errors above or below the visible text are indicated as thin black (warning) or red (error) lines in the vertical scrollbar, as shown in Figure 6-9. This allows you to scroll quickly through the window to reveal other warnings or errors in the file. In your System Preferences, the Appearance pane has a Jump to the Spot That's Clicked option. If selected, clicking in the empty part of the scrollbar jumps immediately to that point in the file. Though this is a system-wide preference change, it makes jumping to relative locations in source files particularly convenient.

Split-Pane Editing

Above the scrollbar is the split pane button. Clicking it splits that editor pane into two independent panes, one above the other, separated by a divider bar, as shown in Figure 6-10.

FIGURE 6-10

Figure 6-10. FIGURE 6-10

You can achieve the same effect using the View

FIGURE 6-10

Holding down the Option key splits the pane horizontally, as shown in Figure 6-11. Choosing to split a pane horizontally or vertically only works for the first pane. After a pane is split horizontally, all subsequent splits are horizontal regardless of whether you select a horizontal or vertical split. The same is true for vertical splits. (This is considered a bug by the Xcode development team and may be fixed in a future version.)

FIGURE 6-11

Figure 6-11. FIGURE 6-11

Unlike the pane divider between the editor pane and the details list, the divider between editing panes does not respond to a double-click. However, it is possible to drag the divider all the way to one edge if you want to hide a pane from view. Drag it back out to the middle again, or close the visible pane, to reveal the hidden pane.

The panes that result from a split are truly independent editing environments. The "Jumping to Other Files" section explains how to switch from one file to another in the same pane. You can do this with split panes, which allows you to edit two or more different files in a single editor window — very handy for editing a code file and its header in the same window. Notice back in Figure 6-11 that the right pane is displaying the MakePromiseViewController.m file and the left pane is editing its companion .h file.

Gutter

The gutter is the shaded bar running down the left edge of the editor pane. If it is not visible, enable it by selecting Show Gutter in the Text Editing pane of the Xcode Preferences. The gutter, shown in Figure 6-12, can display a variety of annotations.

FIGURE 6-12

Figure 6-12. FIGURE 6-12

The gutter displays errors or warnings for a particular line, breakpoints, the current execution location of the debugger, and (optionally) line numbers. The display of line numbers is set in the Xcode Preferences. Warnings and errors are indicated by the yellow caution and red stop-sign symbols. Breakpoints show up as wide blue tabs. Active breakpoints are dark blue. Inactive ones are light grey. A large red arrow indicates where program execution is currently paused in the debugger.

Clicking an error or warning icon in the gutter toggles its description in the text, enabling you to hide error descriptions selectively — which can be a bit distracting if you're trying to fix the problem.

Clicking a breakpoint alternately enables or disables the breakpoint. You can set new breakpoints by clicking anywhere in the background of the gutter. Breakpoints can only be set in file types that Xcode recognizes as program source (C, C++, Objective-C, Java, AppleScript, and so on). You cannot set a breakpoint in XML or other types of non-program text files. You can relocate breakpoints to another line by dragging them there, or delete them by dragging them out of the gutter. Right/Control+click a breakpoint, or in the gutter, to add, remove, edit, or review breakpoints. Double-clicking a breakpoint opens the Breakpoints window. See Chapter 18 for more about breakpoints.

Navigation Bar

The navigation bar, shown in Figure 6-13, occupies the top edge of the editor pane and contains several status and navigation controls. You can hide the navigation bar of the active editor pane with the View

Navigation Bar
FIGURE 6-13

Figure 6-13. FIGURE 6-13

The following table lists the functions of the navigation bar controls.

CONTROL

FUNCTION

File History

Jumps to a file that has been edited in this pane

Functions

Jumps to a function, definition, or marker in the file

Bookmarks

Jumps to a bookmark set in the file

Breakpoints

Jumps to a breakpoint set in the file

Class Hierarchy

Jumps to related class definitions

Included Files

Jumps to an included file, or a file that includes this file

Counterpart

Jumps to the counterpart of this file

Lock

Locks or unlocks the file

The Lock button toggles the lock (read-only) attribute of the file. If you lock a file, or the file was locked when it was opened, the editor will be in display-only mode. If you attempt to change the document, Xcode warns you that you cannot edit the file. You can override this mode in the dialog box and make changes to the document, but that does not change the permissions of the file and you will not be able to save changes until the file is made writable. Unlocking a file automatically switches the editor to its normal editing mode. See the option Save Files As Writable in the "Display Options" section of this chapter.

Note

Numerous Xcode features rely on knowledge about your program's symbols and source files obtained from the Code Sense index. This includes features like jumping to a symbol definition, the Class Hierarchy menu, Included Files menus, and auto-completion — just to name a few. By default, Code Sense is enabled for all projects so this shouldn't present an obstacle, but if any of these features aren't working, see the "Code Sense" section in Chapter 7. You may need to turn on Code Sense or reindex your project.

All of the other navigation controls are explained in the "Navigating Within a File" section, later in this chapter.

DISPLAY OPTIONS

The appearance of an editor pane can be customized in a number of different ways and a variety of options determine how the text itself is interpreted and displayed. The following table lists the principal display options.

DISPLAY OPTION

COMMAND

EFFECT

Line Wrap

View

DISPLAY OPTIONS

Wraps lines wider than the window to the next line

Show Control Characters

View

DISPLAY OPTIONS

Makes control characters visible

Show Spaces

View

DISPLAY OPTIONS

Makes space (ASCII 32) characters visible

Show Issues

View

DISPLAY OPTIONS

Shows message bubbles in the gutter

Navigation Bar

View

DISPLAY OPTIONS

Shows the navigation bar

Status Bar

View

DISPLAY OPTIONS

Shows the status bar

Toolbar

View

DISPLAY OPTIONS

Shows the toolbar

Text Wrapping

The View

Text Wrapping

Invisible Characters

Control characters and the space character are normally invisible. Two more commands in the View

Invisible Characters

The font and size of the text used for all editor panes are set in the Fonts & Colors tab of the Xcode Preferences. These settings are described in the "Syntax Coloring" section of Chapter 7.

Global Display Options

Several global settings control the appearance of editor panes for all windows. These are in the Text Editing tab of the Xcode Preferences, as shown in Figure 6-14.

FIGURE 6-14

Figure 6-14. FIGURE 6-14

Editor Pane Display Options

Show Gutter enables the display of the gutter in regular editor panes. Without the gutter, you cannot see or set breakpoints or find where the execution of the application is currently paused. Because of this, the gutter is automatically displayed whenever you start a debugging session, and is hidden again when the debugging session ends. The editor pane in the Debugger window always shows a gutter.

Show Line Numbers displays the number of each line in the gutter. The Show Gutter option must be enabled for line numbers to be visible.

Show Column Position adds a column number to the filename of the current file in the history control of the navigation bar. The navigation bar must be visible for this option to have any effect. When this option is enabled, the name of the current file indicates both the line and column number of the current insertion point or the beginning of the text selection. If the option is disabled, only the file's name and line number are displayed.

The code folding ribbon is described in the "Code Folding" section of Chapter 7. The Code Focus option actively highlights the code block your cursor is currently hovering over. You may find it amazingly useful or merely annoying — perhaps both.

Turning on the Show Page Guide option causes a vertical line to be drawn at the column number specified in the Display at Column field. Some coding styles require all program text to fit within a certain number of columns. If you are adhering to such a coding style, or are formatting text for a fixed-width output device, the page guide is very useful. Note that the page guide is based on the em-width of the font (traditionally, the width of a capital M) and is only accurate when you're using fixed-width fonts.

Editing Options

The Editing Options consist of Insert Opening Bracket and Select to Matching Brace options.

The Insert Opening Bracket option is a gift to Objective-C programmers. Objective-C statements are enclosed between square brackets, and can be nested like this:

[self setDelegate:[[[MyDelegate alloc] init] autorelease]];

A persistent problem for Objective-C programmers is the situations where they have failed to insert enough opening braces at the beginning of the statement and end up with mismatch brackets at the end, like this statement:

[[MyObject alloc] init] autorelease];

Turning the Insert Opening Bracket option on automatically inserts the missing opening bracket whenever the programmer types an unbalanced closing bracket.

The Select to Matching Brace option is useful in structured languages that use braces, brackets, parentheses, and quotes to delimit blocks of text or code. With this option enabled, double-clicking any of the following characters selects the block of code/text enclosed by it and its matching delimiter:

{ [ ( ' " ) ] }

For example, double-clicking a single or double quote selects a string. Double-clicking an open parenthesis selects the parenthetical statement it encloses. Double-clicking a curly brace selects an entire block of code. The editor takes nested delimiters into account.

The Omit Braces in Selection option refines this feature by determining whether the text selected will include the delimiters in the selection, or just the text between the delimiters.

Save Options

The Save Options are an eclectic set of options that deal with file permissions and line endings. The Save Files as Writable option causes Xcode to set the POSIX write permission of a file when it is saved. With this option off, Xcode preserves the POSIX write permissions the file had before it was saved. That is, if the file were read-only it will be left read-only. When opening a read-only file, Xcode puts the editor pane in display-only mode. Any attempt to change the file is met with a warning, as shown in Figure 6-15. This is mostly to prevent you from trying to edit read-only files that belong to frameworks.

FIGURE 6-15

Figure 6-15. FIGURE 6-15

Clicking the Allow Editing button puts the editor pane in its normal editing mode, but it does not change the permissions of the underlying file. In this state, Xcode refuses to save the file from the Save All window. However, you can save the file by using the File

FIGURE 6-15

Set the Save Files as Writable option and Xcode will not restore the read-only permissions after a save, leaving the file writable. After the save, the file will behave like any other writable file.

This behavior applies to the POSIX write permissions for the file. The other method of making a file unwritable is to set its POSIX immutable flag. (On an HFS filesystem, this flag is synonymous with the HFS locked attribute.) You can set or clear this flag by using the Lock button in the navigation bar, or in the Get Info window for the file in the Finder. The POSIX immutable flag is never overwritten by Xcode, making it a more secure method of preventing changes to a file than merely denying write permission. A locked file behaves the same as a file that lacks write privileges, except that File

FIGURE 6-15

File Encoding

The remaining options in the Text Editing tab deal with line endings and character encoding. Under Line Encodings, the For New Files option determines the line endings for files created in Xcode. The choices are to end each line with a single LF character (Mac OS X or UNIX format), a single CR (Mac OS 9 and earlier format), or a CR+LF sequence (Microsoft DOS format). Unless you have some specific reason to use CR or CRLF line endings, all text files should be written using LF. The For Existing Files option determines the line encoding for files that are saved in Xcode. If this option is set to something other than Preserve, any file saved in Xcode will have its line encoding automatically converted into the selected format. The Preserve setting saves the file in whatever line encoding format it had when it was opened.

Use the Default File Encoding option to choose the character encoding that will be used for any file where Xcode does not know its character encoding. This applies to existing text files being added to a project, or any text file opened in Xcode that does not belong to an open project. If an open project contains a source file item that refers to the file being opened, the character encoding recorded in that source item is used.

NAVIGATION WITHIN A FILE

You'll probably spend more time moving around in your source code than you'll spend writing it. Programming just isn't a linear activity. One rarely sits down and types out a function of any consequence from start to finish. Knowing how to move around your source code quickly and decisively will greatly enhance your efficacy.

Cursor Movement

Start with just moving around in a single source file. The following table lists the key combinations that simply move the cursor around in the text.

Note

All of the key combinations in this chapter are based on the key binding set named "Xcode Defaults." This is the default set when Xcode is installed. Key bindings — the mapping of key combinations to actions — are extremely flexible and can be customized extensively. Xcode includes key binding sets that approximate the key combinations used in BBEdit, Metrowerks' CodeWarrior, and the venerable MPW system. You are also free to devise your own key binding sets. See Chapter 23 for a complete description of key bindings and how to alter them. If you have changed the key bindings in the Xcode Preferences, you may want to set them back to the Xcode Default set while working through this chapter.

KEY COMBINATION

CURSOR MOVEMENT

Right arrow, Control+F

Next character

Command+right arrow, Control+E

End of line

Option+right arrow

End of next word

Control+right arrow

End of next subword

Left arrow, Control+B

Previous character

Command+left arrow, Control+A

Beginning of line

Option+left arrow

Beginning of previous word

Control+left arrow

Beginning of previous subword

Up arrow, Control+P

One line up

Command+up arrow

Beginning of document

Option+up arrow

Previous beginning of line

Down arrow, Control+N

One line down

Command+down arrow

End of document

Option+down arrow

Next end of line

Option+Page Up

One page up

Option+Page Down

One page down

Memorize this table or earmark this page in the book. It will save you an immense amount of time navigating your source code. The most important thing to remember is that the amount of cursor movement increases depending on the modifier key used with the left or right arrow keys, as shown in Figure 6-16. These are, in increasing order or magnitude: none, Control, Option, and Command.

FIGURE 6-16

Figure 6-16. FIGURE 6-16

A word in Xcode is a run of letters, numbers, or the underscore character. A subword is a capital letter followed by a run of lowercase letters, a run of numbers, a run of uppercase letters, or a run of underscore characters between subwords. Leading and trailing underscore characters do not count as subwords.

Emacs

You may have noticed a few odd synonyms for some of the cursor movements, like Control+P to move up one line, or Control+E to move to the end of the line. Xcode key bindings emulate a number of the standard Emacs editor commands. If you're used to using Emacs, you will want to explore the key bindings in the Xcode Preferences to see what Emacs control sequences are supported. This book doesn't go into all of the Emacs commands that are supported by Xcode, but the following table provides a couple of examples.

KEY COMBINATION

ACTION

Control+Space

Sets the mark from the current position

Control+X Control+X

Swaps the current position with the mark

Emacs maintains the concept of a "mark," which is simply a saved location in the file, much like a bookmark. You can set the mark by pressing Control+spacebar. You can also "swap" the mark with the current cursor position or selection by pressing Control+X Control+X (that's Control+X twice in a row). The current cursor position or selection becomes the new mark, and the cursor position or selection is moved to the previous mark. This can be very handy when copying and pasting between two different sections of the same file.

Scrolling

Besides the scrollbar controls, key combinations also exist that scroll the text without changing the current cursor position or selection, as listed in the following table.

KEY COMBINATION

SCROLL MOVEMENT

Page Up, Control+up arrow

One page up

Page Down, Control+down arrow

One page down

Home

To beginning of document

Command+Home

One line up

End

To end of document

Command+End

One line down

Command+J

Jump to Selection

These can often result in scrolling the text so that the current cursor position is no longer visible. Every cursor movement includes an implied request to scroll the window so that the new cursor position is visible. To scroll the window so that the current cursor or selection is visible again, use the Edit

Scrolling

Jumping to Functions, Breakpoints, and Bookmarks

The navigation bar provides several tools for navigating to locations within the current file, as shown in Figure 6-13.

All of these controls are drop-down menus. Select an item in the menu and the cursor moves immediately to that location in the file. Keyboard shortcuts also exist for these menus, as listed in the following table. Using one of the shortcuts drops the menu down. You can then navigate the menu with the up and down arrows or by typing the first few letters of the desired item. Press Return when the desired item is highlighted. Press Esc to dismiss the menu.

KEYBOARD SHORTCUT

NAVIGATION MENU

Control+1, Control+Option+1

File History

Control+2, Control+Option+2

Functions

Control+3

Class Hierarchy

Control+4

Bookmarks

Control+5

Breakpoints

Control+6

Included Files

The File History, Class Hierarchy, and Included Files menus are described a little later in the "Jumping to Other Files" section. The remaining menus navigate within the current file.

Functions

The Functions menu, shown in Figure 6-17, parses the definitions in the source file and dynamically builds a list of functions, classes, methods, types, defines, and markers. This is one of the syntax-aware editing features of Xcode and only works when you're editing file types that Xcode recognizes as being program source files.

FIGURE 6-17

Figure 6-17. FIGURE 6-17

The menu includes an item for each of the following that Xcode discovers in your source code:

  • A class, method, or function (declaration or definition)

  • A type (typedef) declaration

  • #define directives

  • #pragma mark directives

  • Any comment that contains the (case-sensitive) text:

    • MARK:

    • TODO:

    • FIXME:

    • !!!:

    • ???:

Normally, the menu is in the order that the declarations appear in the file. Hold down the Option key when clicking the menu or using the keyboard shortcut to sort the items in alphabetical order. Method names in Java and Objective-C classes are sorted as though their names were fully qualified (for example, MyReader::isEOF), so all of the methods for a class cluster together in the list, subsorted by method name. You can choose to switch the default order by setting the Sort List Alphabetically option in the Code Sense pane of the Xcode Preferences. When this option is set, the list is sorted alphabetically by default and in file order when the Option key is used.

Declarations are italicized in the menu. Declarations can be excluded by turning off the Show Declarations option in the Code Sense pane of the Xcode Preferences.

The most flexible means of adding arbitrary entries to the Functions menu is to insert a #pragma mark directive to your source code, as shown in Figure 6-17. The statement #pragma mark - adds a menu divider.

Finally, the Functions menu acts as a location indicator. Whenever the cursor or selection is in a definition or the body of a class, function, or method, the menu indicates the name of the current location. When the menu is popped open, the current location is indicated with a check mark. If the cursor position is not within any definition, the message "<No Selected Symbol>" is displayed.

Bookmarks

The Bookmarks menu lists all of the bookmarks set in the file. It does not list bookmarks set in other files. Use the Bookmarks window or the Bookmarks smart group in the project window to see those. Bookmarks are always listed in the order they appear in the file.

To set a bookmark, position the cursor or make a selection and choose the Edit

Bookmarks

Breakpoints

The Breakpoints menu jumps to any breakpoints set in the file. Each breakpoint is displayed as the function or method name containing the breakpoint plus a line number.

Jumping to Other Files

Just as important as being able to move around quickly within a file is the ability to move quickly between files. You've already seen how to open and browse files from the project window, but Xcode provides a variety of other ways to switch directly from one file to another.

File History

The File History menu in the navigation bar maintains a list of the files that have been displayed in that editor pane, as shown in Figure 6-18. Select a file from the list and the pane switches to that file. The keyboard shortcut for the File History menu is Control+1.

FIGURE 6-18

Figure 6-18. FIGURE 6-18

File history is maintained individually for each editor pane. Even multiple panes within the same window have their own history. For the editor pane in the project window, or when you're using the Grouped window mode, this can be quite a long list. For separate editor windows, it tends to be just the file that is being edited. All new panes have an empty history, and closing a pane discards the history for that pane. The only exception is when Xcode saves the state of a window in the project document. It always does this for the project window, and it saves the state of other open windows if the Save Window State option in the General preferences is set. Thus, the history of the project window's editor pane is always preserved and so is, possibly, the state of all open editor windows.

To limit (or not) how much file history is retained, the File History menu has two special items, as previously shown in Figure 6-18. The Clear File History item does just that. It forgets all previously visited files except the current one. The History Capacity item sets the limit for the number of files in the list. The capacity defaults to Unlimited. For most editor panes, this isn't an issue because they rarely get past two. For editor panes, like those in the project window that are constantly being reused, you may want to limit the size of the history, or the list may become unwieldy. Like the file history itself, this setting is stored separately for each editor pane and is saved in the window's state.

The two arrow buttons to the left of the File History menu move through the history list, like the previous and next buttons in a browser. The File History menu lists each file in alphabetical order, but the history buttons are really a browser-like history of the locations that have been visited, in the order that they were visited. Clicking the Previous button takes you to the location previously visited, not the file above the current one in the menu. It is unlike the File History menu in two other respects: it remembers your location within each file, not just files. This appears as a filename and line number, such as "main.c:27." A file and location may occur more than once. The history and the menu are both limited to the number of items set in the History Capacity menu.

Aggregate History

Hold down the Option key when popping up the File History menu to see the aggregate file history. The aggregate file history is a combined list of the history items from every open window. Be careful about using the feature too liberally with multiple projects open, because the list will include files from all of your projects. You can easily open the project window for project A and switch to a source file that belongs to project B.

Adding an Arbitrary File to the History

Xcode windowing options tend either to open all files in a single editor pane, or every file in a separate window. Consequently, the file history consists of every file you've ever visited or just the file opened in that window. There are some times when you'd like to work with a select number of files in a single, separate, editor window. You have three ways of accomplishing this.

The first method is to use the Group window, described in the "Using a Group Editor Window" section earlier. This directs all new files to the same window. Use the File History menu to switch between all of the files that have occupied that window.

The second method is to use the aggregate file history to switch to a file that has been visited in some other editor pane. Once the file is brought into the current window, it becomes part of its history. This is the simplest way of adopting a file that is, or has been, opened elsewhere.

The last method is to drag a file and drop it directly into the navigation bar, as shown in Figure 6-19. This switches the editor pane to that file and adds it to its history.

FIGURE 6-19

Figure 6-19. FIGURE 6-19

The source of the drag can be a source item in the project window, a file from the Finder, or the file icon in the title bar of a document window. This technique can only be used to add one file at a time.

Included Files

The Included Files menu is another syntax-aware feature for C and C-like language files. Each #include or #import directive that it finds is listed in the top portion of the menu, as shown in Figure 6-20. Selecting an item from the list jumps to that file. The keyboard shortcut is Control+6.

FIGURE 6-20

Figure 6-20. FIGURE 6-20

When used in a header file, the Included Files menu also lists the files that include this file at the bottom of the menu. In Figure 6-20, the current file, MyViewController.h, includes one header file, UIKit.h, and is included by two other files in the project, AppDelegate.m and MyViewController.m.

Switching Between a Header and its Source File

The convention for C, C++, and Objective-C languages is to place the declarations for functions and data types in a header file with an .h or .hpp filename extension, and write the implementation of those functions in a source file of the same name. If you use this convention, Xcode lets you quickly jump back and forth between the two using the View

Switching Between a Header and its Source File

Whether the counterpart file opens in a new editing window depends on your layout style and the setting of the Open Counterparts in Same Editor option in the General pane of the Xcode preferences.

Jumping to a Definition

As mentioned earlier in this section, one of the most useful navigation tools in Xcode is the Edit

Jumping to a Definition

Jump to Definition uses the syntax-aware symbols table to index all of the class, function, type, and constant names that are defined in your project. Command+double-clicking a word, or selecting a symbol name and choosing Edit

Jumping to a Definition

If there are multiple symbols with the same name, or if you choose a class name with multiple implementations, Xcode pops up a list of the possible matches, as shown in Figure 6-21. Select the desired symbol and the editor jumps there.

FIGURE 6-21

Figure 6-21. FIGURE 6-21

Code Sense indexing must be enabled for this feature to work. See the "Code Sense" section in Chapter 7.

EDITING

All of the standard text selection and editing features supplied by the operating system's text editing framework work in Xcode. If you need a refresher on the basics, refer to the Mac OS X Help. The following sections highlight a few obscure features that are particularly useful when editing source code. In addition, Xcode adds its own set of features and commands.

Selecting Text

All of the standard text selection gestures work in Xcode. Click and drag to select some text. Hold down the Shift key to extend a selection. Selecting text by dragging is dependent on timing; see the "Drag and Drop" section later for an explanation.

Note

The standard Mac OS X text editor is sensitive to word boundaries when extending text selections. It's an obscure quirk that most people don't notice, but may impact your coding. When you Shift-click to extend a selection, Xcode examines the other end of the selection (the end not being moved). If that end lies on a word boundary, the end being extended snaps to word boundaries. If the stationary end is in the middle of a word or between non-word characters, the extended end can be positioned at any character. This makes it very quick and easy to extend a selection to include additional words or symbols, because you don't have to select the edge of the word; dragging anywhere into the word will suffice. If you start with a selection on a word boundary, and want to extend it to a non-word boundary, extend the selection using the keyboard (Shift+right arrow or Shift+left arrow) instead. This might be a good time to review the cursor movement modifiers back in the "Cursor Movement" section.

Selecting Columns

One of the more obscure features of the editor is the ability to select columns of text. You can select all of the characters between two column positions across multiple lines by holding down the Option key and dragging out a selection. Figure 6-22 shows a column selection. Hold down the Shift and Option keys to extend or contract an existing column selection.

FIGURE 6-22

Figure 6-22. FIGURE 6-22

You can copy the selected characters to the clipboard or delete them. If you copy the selection, the clipboard will contain the selected characters of each line on separate lines. Lines that have no characters selected (lines shorter than the first column) are not included. You cannot paste into a column selection or otherwise replace a column with multi-line content.

Selecting Code Blocks

The Edit

Selecting Code Blocks

This command is similar to, and independent of, the Select to Matching Brace option in the Text Editing pane of the Xcode Preferences, described earlier in the "Editing Options" section. This command, however, works only with braces and brackets.

Jumping to a Line or Character

The Edit

Jumping to a Line or Character
FIGURE 6-23

Figure 6-23. FIGURE 6-23

Enter the position within the file that you want to select. The radio buttons determine whether the position will be interpreted as a character offset or a line number.

Press the Return key and that line or character is selected in the file and the Goto window closes. Alternatively, you can click the Select button. This also selects your chosen position, but leaves the Goto window open. If you check the Auto-Update option, the position in the Goto window continuously updates to reflect your current position within the file.

Deleting Text

The text editor provides several useful variations of the standard delete key for deleting text adjacent to the insertion point, as listed in the following table.

KEY COMBINATION

DELETES

Delete, Control+H

One character to the left of the cursor

Control+Delete

From the cursor to the beginning of the previous subword

Option+Delete

From the cursor to the beginning of the previous word

Command+Delete

From the cursor to the beginning of the line

Delete-right, Control+D

One character to the right of the cursor

Control+delete-right

From the cursor to the end of the next subword

Option+delete-right

From the cursor to the end of the next word

Control+W

From the cursor to the current mark

The Delete key, just above the Return key (sometimes labeled

Deleting Text

The delete keys follow the same pattern that the right and left arrow keys do. The amount they delete increases depending on the modifier used: either none, Control, Option, or Command. The one exception is the combination of Command+right-delete, which doesn't work; use Shift+Command+right-arrow to select to the end of the line, and then press the Delete key.

Control+H and Control+D are Emacs synonyms for Delete and delete-right. Use these if you prefer or if you don't have a delete-right key on your keyboard. These control key equivalents cannot be combined with the Option or the Control key modifiers. The Emacs-centric Control+W command deletes from the current cursor location to the location of the mark, previously set with Control-spacebar or Control+X Control+X.

Drag and Drop

A text selection can be dragged around within a document, between documents, and between Xcode and other applications.

A text selection and a text drag use the same gesture: click, move, and release. The difference is in the timing. To drag out a new text selection, press down the mouse button and move the mouse immediately. The cursor remains a text cursor. To start a drag, press down the mouse button and wait. After a very short delay (less than a second) the cursor turns into an arrow. You are now dragging the text selection. You can customize this delay to suit your mousing speed. See the discussion of the NSDragAndDropTextDelay expert setting in Chapter 23.

Press down the Option key before dropping the text to make a copy. Dragging between documents always performs a copy. Dragging from other applications inserts the text equivalent of the object being dragged. Dragging file icons from the Finder or the project window inserts the URL of the file, not the contents of the file itself. To insert the contents of a file, open that file in Xcode, choose Edit

Drag and Drop

Most lists, displays, and fields in Xcode can be the source of a drag even when they are not editable. How useful this is will vary, but keep it in mind before you reach for a yellow pad to write something down. You might simply be able to drag it somewhere to keep it. Drag any text selection to the desktop or an open Finder window to create a clipping file containing that text. This is a handy way of saving or "setting aside" a chunk of code while you experiment.

Font and Text Styles

Program source files are plaintext files that do not include any font, style, color, or other typographic information. Logically then, the commands and tools in the Edit

Font and Text Styles

When you use Xcode's RTF (styled text) editor, the commands in these menus perform as expected.

Saving Files

All editor panes, except for ones just created with the File

Saving Files

COMMAND

ACTION

Save (Command+S)

Writes the contents of the editor pane to its file.

Save As... (Shift+Command+S)

Enables you to create a new file and writes the text to that new file. The new file becomes the file associated with that pane. If the original file was referred from a project, the path and name of that source item is also updated to refer to the new file. The original file is not altered, and the project no longer has a reference to it. Use this command to rename a file while preserving a copy of the original.

Save a Copy As (Shift+Option+Command+S)

Like Save As, this command enables you to choose a new file, write the contents of the editor pane to it, and leave the contents of the original file untouched. But that's where it stops. The file associated with the editor pane is not changed, and it still refers to the original file. A subsequent Save command writes any changes to the original file. Nothing in the project is altered. This command is useful for making a snapshot of a file, or for quickly creating a new file that is a copy of an existing one without altering the project.

Save All (Option+Command+S)

This command presents a dialog box, shown in Figure 6-8, that lists all modified file buffers being held in memory. You can choose to save all, or only some, of them in a single command. The Save All dialog box was described earlier in this chapter in the "Closing and Saving Editor Panes" section.

The Revert to Saved (Command+U) command is the opposite of the various Save commands. Instead of writing the changes to the file, it discards any changes made since the file was opened or saved and re-reads the text from the file. Xcode presents a warning beforehand, shown in Figure 6-24, ensuring that you really do want to abandon all the changes you've recently made. You cannot recover these changes once the Revert to Saved command has executed.

FIGURE 6-24

Figure 6-24. FIGURE 6-24

Undo

Xcode's undo features work pretty much the way they do in most modern applications, but a couple of differences exist. Undo history is maintained on a per-file basis. Until the file is saved and all editing panes that contain it are closed, Xcode maintains the undo history for the file, and all editing panes showing the same file share the same undo history.

Each atomic editing action is recorded as a step in the undo history. An "atomic" action would be typing some sequence of regular text characters, navigation, auto-completion, using the Tab key, deleting text, cutting, pasting, or any other menu command that changes the contents of the text buffer.

The Edit

Undo

Warning

Undoing a Cut or Copy command does not restore the previous contents of the system's clipboard. It only restores the state of the editor pane prior to the Cut command.

The Redo command performs the complement of the Undo command. It takes the most recent action moved to the redo list, performs it again, and adds it to the undo history. Together, the Undo and Redo commands are like a time machine, allowing you to step forward and backward through the history of the file's changes until you find the state of the file you want.

Any new change made to a file erases the redo list. If you go back in time and make a different choice, you can no longer visit the future that contained the original choice. The Revert to Saved command empties both the undo and redo information for a file.

The Save command does not alter the undo or redo information for a file. This means it is possible to undo changes made to a file after it has been saved. Whenever you try to undo the last action that occurred before a file was saved, Xcode presents a dialog box like the one shown in Figure 6-25.

FIGURE 6-25

Figure 6-25. FIGURE 6-25

Some developers find this dialog box annoying. Chapter 19 explains how to set the XCShowUndoPastSaveWarning advanced setting to disable that warning.

SHELL SCRIPTS

If you've been around the Macintosh platform long enough to remember MPW (the Macintosh Programmer's Workshop), you may be missing one of its more intriguing features. Every text window in MPW was a "live" worksheet, capable of executing any MPW command. In fact, MPW made no real distinction between a text document and a shell window. This made for some interesting possibilities.

Xcode resurrects this ability, in a fashion, with the hidden Execute Script command. This command is normally bound to the Control+R key combination. It doesn't appear in any of the menus. Select any text and press Control+R. The selected text is executed in your default shell (bash, by default). The output of those commands is inserted into your text file immediately after the selected script, as shown on the right in Figure 6-26.

FIGURE 6-26

Figure 6-26. FIGURE 6-26

The current directory is always set to the active project folder prior to execution, so you can refer to project files using project folder–relative paths. A new instance of the shell is used for each invocation, so aliases and shell variables are not persistent. Note that the shell's stdin is set to /dev/null, making it impossible to use commands that prompt for user input, such as sudo.

SPELL CHECKING

Programmers are notoriously bad spellers. Thanks to the Cocoa underpinnings of Xcode, the editor inherits the standard Mac OS X spelling checker. The spelling checker is great for correcting comments and documentation, thus avoiding the scorn and ridicule of the documentation department that is inevitably populated with English majors and spelling bee champions. The spelling checker is essentially useless for code. Avoid adding program symbols or language keywords to your user dictionary. Your login account has only one user dictionary, and filling it with programming symbols defeats its usefulness in other applications.

Interactive Checking

Start the interactive spelling checker with the Edit

Interactive Checking
FIGURE 6-27

Figure 6-27. FIGURE 6-27

Checking starts at the text cursor or the beginning of the current selection. Checking is not limited to the text selection; it just starts there. The next word that the spelling checker suspects is misspelled is highlighted in the text and displayed in the entry field of the palette. Above the suspect word is a list of suggested corrections.

The Ignore button adds the suspect word to the temporary ignore list. The spelling checker ignores this word, and assumes that it is spelled correctly, until the next editor session. Use this to teach the spelling checker temporarily about correctly spelled words, without permanently adding them to the dictionary.

The Find Next button skips this word and goes looking for the next suspicious word. The spelling checker still considers the word to be misspelled.

You can immediately replace a word with a suggestion from the Guess list by selecting the suggestion and clicking the Change button, or by double-clicking a suggestion in the list. You can replace the word with any arbitrary text by editing the contents of the text field before clicking the Change button.

If the spelling checker cannot guess the correct spelling of the word, you can help it by editing the suspect word and telling it to guess again using the Guess button. For example, the spelling checker cannot guess that you mean "exhausted" if you've actually typed "eghosted." Replacing the "g" with an "x" and clicking the Guess button, as shown in Figure 6-28, gets the word close enough for the spelling checker to find the correct word.

FIGURE 6-28

Figure 6-28. FIGURE 6-28

The pop-up at the bottom of the palette lets you choose a different language. The Learn and Ignore buttons take the word currently in the entry field and either add or remove it from your user dictionary. To remove a word you previously added, you have to type or paste it into the field before clicking the Ignore button. Your user dictionary is shared by all applications that use the Spelling Checker interface, so add to it wisely and sparingly.

Checking One Word

You can invoke the spelling checker without bringing up the spelling checker palette with the Edit

Checking One Word

This is probably the most useful spell checking command for programmers. After writing a long comment, position the cursor at the beginning of the comment and press Command+;. The spelling checker will skip to the first suspect word in the comment. Once you've corrected all of the English words in the comment, simply go back to writing code.

Checking While Typing

The Spelling menu has an option to Check Spelling as You Type. If selected, words that you just typed or edited are spell checked and highlighted automatically. Note that this does not spell check the entire document, or text that you paste or drag. It only checks the word that your cursor was just in or adjacent to. The word that the cursor is currently in or adjacent to is never highlighted (because it is assumed that you are in the process of changing it).

You may find this feature useless and annoying when you're editing source code, because practically every "word" in your program is going to be tagged as misspelled. However, if you are writing a large amount of documentation in Xcode, you might find it helpful to turn it on temporarily.

FILE ENCODING

Chapter 5 showed you how to change the character and line encoding for one or more files using an Info window. You can alter those same settings for the file being edited using the View

FILE ENCODING

Changing these settings does not, immediately, alter the actual file. The encodings are used to interpret the bytes in the file and turn those codes into Unicode characters for editing. This translation uses the encoding set for the file when it is read. Conversely, when the file is later saved, the Unicode characters in the editor are translated back into bytes using the encoding that is set then.

Problems can arise when you change from one character encoding to another. Some characters cannot be represented in certain encodings or you may have the wrong characters in the editor because the encoding was mismatched when the file was read. For instance, the registered trademark symbol (®) appears in the Unicode, Mac OS Roman, and Windows Latin 1 character sets, but the binary code used to represent it in a text file is different for all three. If the file was written using Windows Latin 1 encoding and you read the file into the editor using Mac OS Roman encoding, the editor displays some other symbol because the value in the file is not the Mac OS Roman value for the registered trademark symbol.

When you change the encoding for a file, Xcode asks if it should convert or reinterpret the characters in the file, as shown in Figure 6-29.

FIGURE 6-29

Figure 6-29. FIGURE 6-29

The Convert button actually does very little beyond remembering the new encoding for the file. The characters are already in their universal form in memory. The "conversion" doesn't actually occur until you save the file. The bytes in the file were read using the old encoding, and will eventually be written using the new encoding. Use this option if the characters in the file are correct and you simply want to save the file using a different encoding. The one thing the Convert button does do is check that all of the characters in the file can be written using the new encoding. Xcode does not allow characters in an editor pane that cannot be encoded when it is saved. If the document contains characters that are illegal in the new encoding, the conversion is not allowed.

Use the Reinterpret button when the encoding is incorrect and the editor has misinterpreted the bytes in the file. If a file containing the registered trademark symbol is encoded using Windows Latin 1, and read using Mac OS Roman, the character that appears in the file is "Æ." To correct this, change the encoding to Western (Windows Latin 1) and click the Reinterpret button. The contents of the file are read again, this time using the Windows Latin 1 encoding, and the ® symbol appears instead. To save this file using Mac OS Roman encoding, change the encoding again — this time using the Convert button.

The Reinterpret button must re-read the bytes in the actual file. The binary encoding of characters is not maintained in memory — only the Unicode characters are. If changes have been made to a file, the Reinterpret button warns you that all unsaved changes will be lost when the file is reinterpreted, as shown in Figure 6-30. You can choose to discard all unsaved changes or cancel. To preserve and reinterpret the file including all of the changes that you've made, cancel the reinterpretation, save the file using the old encoding, and change the encoding again.

FIGURE 6-30

Figure 6-30. FIGURE 6-30

As mentioned earlier, Xcode won't allow you to convert a file if the resulting document would have characters that cannot be encoded. Likewise, the editor won't let you insert a character into a document if the file's encoding won't support it. If you try, you get a warning like the one in Figure 6-31.

FIGURE 6-31

Figure 6-31. FIGURE 6-31

You have the choice of converting your document to Unicode (really Unicode-16) or Unicode-8. Unicode-16 is the "raw" Unicode encoding used internally by the editor. Unicode-16 writes or stores each character as a 16-bit integer word. Most editors, compilers, and other ASCII-oriented programs are not compatible with Unicode-16. Unicode-8 writes the common ASCII (0–127) characters as single bytes and encodes higher-value Unicode characters using a complex system of escape values. Unicode-8 is compact, compatible with many applications, and backwards-compatible with plain ASCII text. If given this choice, convert your document to Unicode-8.

If you don't want to use Unicode-8 or Unicode-16, cancel the insertion. Convert the file to an encoding that supports the characters you are trying to insert, and insert them again.

LOCALIZING FILES

One of the hallmarks of the Macintosh is the ability of programs to transform themselves to accommodate the language, currency, and time conventions of different countries and populations. This is generically referred to as localization. Xcode supports localization of individual project files. It does this by maintaining multiple copies of the file, one for each locale.

Your locale — the locale that your Xcode development system is currently set to — is called the development region. You should always start by creating the version of a file for your development region. When you localize a file, the original file becomes the version for the development region. You can then create variations of the file for other regions.

Normally, you only localize resource files like string lists, images, and NIB documents. Localization requires runtime support, and is usually done for files that are copied into the deployment bundle. The bundle is organized so that all versions are copied into the bundle and the appropriately localized version of the file is loaded based on the locale of the current user. Though it is possible to localize something like a source file, only the development region's version will be compiled.

Creating Localized Versions of a File

To prepare a file for localization, open the Info window for the file's item and click the Make File Localizable button. The file's source item is turned into a group and the existing file becomes the localized version for the development region. In the project structure group, the source item becomes a kind of source group. The top-level item acts as a proxy for the development region's version of the file, equivalent to the original file; that is, opening the item opens the localization for the development region. To open or change settings for an individual locale, expand the group and deal with each version separately.

After you initially localize the file, you can add more localizations by opening an Info window for either the item group, or any specific localization, and clicking the Add Localization button. Enter the name of the localization, or choose one from the pop-up menu, as shown in Figure 6-32. A new file is created by duplicating the current file. The new file becomes the localized version for that region.

FIGURE 6-32

Figure 6-32. FIGURE 6-32

In the project folder, Xcode creates an .lproj subfolder for each localization. All of the files localized for English are in the English.lproj subfolder, all the files localized for French are in the French.lproj subfolder, and so forth. When the file is first localized, a localization folder for the development region is created in the same location, and the file is moved into the .lproj subfolder. The Multiglot project, shown in Figure 6-33, shows the organization of the project and project folder after the MainMenu.nib and InfoPlist.strings files have been localized for English, French, and Spanish.

FIGURE 6-33

Figure 6-33. FIGURE 6-33

Removing Some or All Localizations

To remove a single localization of a file, select the specific localization within the file's group and delete it like you would any other source item.

To remove all localizations of a file, open the Info window for the localized group or any specific localization. Click the Remove All Localizations button. The localization for the development region is moved from the .lproj subfolder back to its original location. The localized group in the project is replaced with a simple source file reference again. Any additional localized versions of the file are left in their respective .lproj folders, but are no longer referred to in the project. If you later localize the file again, Xcode will not automatically pick up the other localized versions. However, if you add a localization for a region that already has a file in its .lproj subfolder, the file is not replaced and it becomes the localization for that region.

PRINTING

Rudimentary printing of editor panes is provided through the File

PRINTING

The text is printed at 72 dpi, which means that it will probably be unacceptably large. Use the scaling feature of the page setup to reduce the size of the text. A scale between 50% and 75% makes for a very readable and compact listing. For an even more compact listing, set the scaling between 80% and 100% and select a two-up page layout.

SERVICES

Xcode, like all well-written Cocoa applications, has access to services. Services are small functions provided by other applications that can be applied to the current selection within another application. To open the URL in the source file shown in Figure 6-34, simply select it and choose the Open URL command from the Services menu.

FIGURE 6-34

Figure 6-34. FIGURE 6-34

What services you have in your Services menu depends entirely on what applications and plug-ins you have installed.

SUMMARY

As you can see, Xcode's editor provides a lot of features designed to make your editing sessions fluid and productive. Learning to use the various navigation controls will make moving around within a file, and between files, quick and efficient.

Though the editor provides many useful features for editing and formatting your code, there's a lot more that it can do for you. The next chapter describes the many syntax-aware features of the editor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset