See the option Save Files As Writable in the “ Display Options ” section of this chapter.. DISPLAY OPTIONS The appearance of an editor pane can be customized in a number of different wa
Trang 1The following table lists the functions of the navigation bar controls
File History Jumps to a fi le that has been edited in this pane Functions Jumps to a function, defi nition, or marker in the fi le Bookmarks Jumps to a bookmark set in the fi le
Breakpoints Jumps to a breakpoint set in the fi le Class Hierarchy Jumps to related class defi nitions Included Files Jumps to an included fi le, or a fi le that includes this fi le Counterpart Jumps to the counterpart of this fi le
Lock Locks or unlocks the fi le
The Lock button toggles the lock (read - only) attribute of the fi le If you lock a fi le, or the fi le 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 fi le You can override this mode in the dialog box and make changes to the document, but that does not change the permissions of the fi le and you will not be able to save changes until the fi le is made writable Unlocking a fi le automatically switches the editor to its normal editing mode See the option Save Files As Writable in the “ Display Options ” section of this chapter
Numerous Xcode features rely on knowledge about your program ’ s symbols and source fi les obtained from the Code Sense index This includes features like jumping to a symbol defi nition, 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
Trang 2Navigation Bar View ➪ Layout ➪ Show Navigation
Bar
Shows the navigation bar
Status Bar View ➪ Layout ➪ Show Status Bar Shows the status bar
Toolbar View ➪ Show Toolbar Shows the toolbar
Text Wrapping
The View ➪ Text ➪ Wrap Lines command toggles between wrapped and unwrapped editor
modes With line wrapping turned on, lines that exceed the width of the window are split at some
convenient point and continued on the next line in the editor When line wrapping is off, long lines
simply continue off the right edge of the editor pane If one or more lines exceed the width of the
editor, a horizontal scrollbar appears at the bottom of the pane
Invisible Characters
Control characters and the space character are normally invisible Two more commands in the
View ➪ Text menu, Show Control Characters (Command+Shift+6) and Show Spaces, make those
characters visible Show Control Characters is particularly useful for fi nding gremlins — illegal
control characters in a source fi le This option does not show any of the normal control characters:
tab, newline, or return Show Spaces marks the location of each ASCII space character with a
spacing bracket Select either command again to toggle them back off
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
Trang 3Editor 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 fi nd 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 fi lename of the current fi le 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 fi le 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 fi le ’ 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 fi nd 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 specifi ed in the Display at Column fi eld Some coding styles require all program text to fi t within a certain number of columns If you are adhering to such a coding style, or are formatting text
FIGURE 6-14
Trang 4[[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 refi nes 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 fi le permissions and line endings The
Save Files as Writable option causes Xcode to set the POSIX write permission of a fi le when it is
saved With this option off, Xcode preserves the POSIX write permissions the fi le had before it
was saved That is, if the fi le were read - only it will be left read - only When opening a read - only
fi le, Xcode puts the editor pane in display - only mode Any attempt to change the fi le is met with a
warning, as shown in Figure 6 - 15 This is mostly to prevent you from trying to edit read - only fi les
that belong to frameworks
Trang 5Clicking the Allow Editing button puts the editor pane in its normal editing mode, but it does not change the permissions of the underlying fi le In this state, Xcode refuses to save the fi le from the Save All window However, you can save the fi le by using the File ➪ Save command directly or by starting
a Build with the Always Save option selected Xcode temporarily makes the fi le writable, writes the changes, and then restores the read - only permissions of the fi le The editor pane remains editable
Set the Save Files as Writable option and Xcode will not restore the read - only permissions after a
save, leaving the fi le writable After the save, the fi le will behave like any other writable fi le
This behavior applies to the POSIX write permissions for the fi le The other method of making a fi le unwritable is to set its POSIX immutable fl ag (On an HFS fi lesystem, this fl ag is synonymous with the HFS locked attribute.) You can set or clear this fl ag by using the Lock button in the navigation bar, or in the Get Info window for the fi le in the Finder The POSIX immutable fl ag is never overwritten by Xcode, making it a more secure method of preventing changes to a fi le than merely denying write permission A locked fi le behaves the same as a fi le that lacks write privileges, except that File ➪ Save does not change the status of the immutable fl ag or write to the fi le Instead, Xcode displays a simple error dialog box explaining that it cannot write to the fi le To make changes to the
fi le, you must fi rst click the Lock control in the navigation bar to unlock the fi le
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 fi les 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 specifi c reason to use CR or CRLF line endings, all text fi les should be written using LF
The For Existing Files option determines the line encoding for fi les that are saved in Xcode If this option is set to something other than Preserve, any fi le saved in Xcode will have its line encoding automatically converted into the selected format The Preserve setting saves the fi le in whatever line encoding format it had when it was opened
FIGURE 6-15
Trang 6Cursor Movement
Start with just moving around in a single source fi le The following table lists the key combinations
that simply move the cursor around in the text
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
fl exible 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
Right arrow, Control + F Next character
Command + right arrow, Control+ E End of line
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
Command + up arrow Beginning of document