Information Technology Reference
In-Depth Information
The forward and back arrows at the top left of the editor are easy to miss, but they're an essential timesaver. They
work like the forward and back buttons on a browser. For example, if you are currently viewing code but you were
previously viewing a UI layout in Interface Builder, the back button switches the editor back to IB for you auto-
matically.
Getting started with code editing
Although code editing seems simple—start typing and stop when you're done—it can take time to get accus-
tomed to the hidden features in Xcode, which include the following:
Code completion: This is a fairly sophisticated feature that makes educated guesses about possible code
as you type. You can insert the suggested code with the Tab key or select a different educated guess from a
floating menu.
Auto-indentation: This indents the cursor position automatically, taking into account preceding code.
Bracket matching: When you type a closing bracket or move the cursor over it with the right arrow key,
the matching open bracket flashes yellow. If there is no matching bracket, Xcode plays a short warning
sound.
Bracket generation: Type a new a method signature and an opening curly bracket, then type Return.
Xcode adds a closing curly bracket and positions the cursor on the first blank line of the method.
Square bracket balancing: For square brackets only, Xcode adds an opening square bracket when you
type a closing square bracket. While this feature can be useful, it lacks intelligence, and sometimes you need
to remove the brackets it creates.
The easiest way to master these features is to experiment with them. They're often very helpful, but occasionally
you may need to use them in a lateral way. For example, the simplest way to insert a new line of code is to click
with the mouse at the end of the previous line and type Return. Xcode inserts a blank line and indents the curs-
or as needed. Placing the cursor before the insertion position doesn't do what you want.
Using code completion
If you've used Code Sense in Xcode 3, Xcode 4's code completion works slightly differently. The easiest way to
illustrate it is with an example.
Create a new project using the iOS View-based application template. Save it with any name; in this example, I
use myCleverApp. Open the Project Navigator, and select the myCleverAppAppDelegate.m file so the
code appears in the editor.
Click with the mouse at the end of a line of code in any method. In this example, I use the application
didFinishLaunchingWithOptions: method. But code completion isn't limited to any one method or
class; it works throughout a project.
Type [UIVi , as shown in Figure 4.20. Code completion pops up the menu shown in the figure. UIView is
highlighted to indicate that this is code completion's best guess. To accept the guess, type the Tab key or the
Return key. Either inserts UIView in full.
FIGURE 4.20
Xcode 4's Code Sense feature has been redesigned. But if you're used to Xcode 3, you'll find much of it remains
familiar.
Search WWH ::




Custom Search