Sei sulla pagina 1di 2

CS193P Handout #3

Fall 2008 Doll/Marcos

Tips & Tricks for a Happier Xcode Existence


Keyboard Shortcuts
There are a number of keyboard shortcuts in Xcode which, if you take the time to commit them
to memory, will pay back on the investment many times over. Here’s a list of the ones that I find
most useful; I use all of these on a daily basis. I’ve listed the menu item (where one exists), de-
fault keyboard shortcut and a brief description

Edit→Completion List: Option-Escape


Pops up a popup list of recognized completions. The list is sensitive to where you’re
typing. It will complete methods, instance variables, global variables, constants, struct
members, etc. For example if you’ve just typed: “[myString setIn”, Xcode will notice that
you’re calling a method on an NSString and only show you methods for the NSString
class starting with “setIn”. The list can be sorted strictly alphabetically or by “best
guess” (there’s a little icon in the popup list that lets you toggle). I run with mine set
to “best guess” and that does a good job of guessing. While the list is up you can con-
tinue typing and it will narrow the result set. Use the up/down arrows to choose a
different item and hit return or tab to select it.

Edit→Next Completion: Control-period


An alternative to the full-blown popup list is to simply use Next Completion to do an
inline completion of the best guess. If you don’t get what you want the first time you
can repeatedly invoke it to cycle through the completions.

Edit→Select Next Placeholder: Control-forward slash


When choosing a method that takes arguments via completion using one of the
above methods you’ll see something like:

[self setValue:<#(id)value#> forKey:<#(NSString *)key#>

The “<#...#>” notation are called placeholders. By using the Select Next Placeholder
shortcut you can quickly jump from one argument to the next. The logic here is
pretty straightforward, Xcode just searches forward in the text file from where the in-
sertion caret is looking for one of these blocks and then selects it. In this example I
had typed “setVal”, did a Next Completion which filled out the method and then doing
Select Next Placeholder it makes filling in the arguments really pretty quick.

View→Switch to Header/Source File: Command-Option-Up arrow


This keyboard shortcut is the same as the button on the header above the text
area. It just jumps back and forth between the .h and .m (or .c, .cpp, etc) file.

Jump to Implementation/Interface: Command-double click on text


When you command-double click on a method name Xcode will try to jump to the
method implementation (if it can find the source file containing it) or at least to the
method interface. Unfortunately it doesn’t always get it right, notably when double
clicking on a method that takes multiple arguments. This is also handy for double
clicking on class names to jump straight to the header file for that class.

Page 1 of 2
CS193P Handout #3
Fall 2008 Doll/Marcos

Jump to Documentation: Option-double click on text


Similar to the Jump to Implementation, option-double clicking on something will pop
up the documentation window and try to find what you clicked on. If what you
clicked on isn’t found then you’ll get an empty search result.

Format→Re-Indent: No default keyboard shortcut


Reindents the text that’s selected. There’s no default keyboard shortcut but you can
add one (and change any of the above) in the Key Bindings Preference panel in the
“Menu Key Bindings” tab. Personally I use command-shift-I (that’s an “eye”).

File→Open Quickly: Command-Shift-D


Pops up a panel where you can type a file name. This is most frequently used for
opening header files from the Cocoa frameworks. You can type in a name without an
extension and Xcode will first try to find an implementation file and if it can’t find one
will look for an interface file. The text field is not case sensitive so you can type “nsta-
bleview” and it’ll find the right file.

Preferences
In a similar way to how the learning the key shortcuts above will make life easier for you, setting
a couple preferences can improve your Xcode experience. Here’s a list of what I recommend:

• In the Code Sense pref pane turn off the “Indicate when completions are available”. It tends
to slow things down
• Also in the Code Sense pane, turn off the “Automatically suggest on member call / access”. I
don’t recall if this is on by default or not but if it’s on it can be a frequent source of “spinning
beachballs” in the Xcode editor.
• In Building, set the “Place Build Products in:” option to “Customized location:” and specify a
directory that you can write into. This will keep all the build files outside of your source tree
which makes submissions easier and keeps your source unpolluted. If you’re working on a
LaIR machine you’ll probably have to set it to something like “~/build”, although I’m not posi-
tive how that will work. If this doesn’t work out, let me know.
• In Indentation, make sure “Syntax-aware indenting” is enabled. I check all the “Automatically
indented characters:” feel free to check what works for you.

Page 2 of 2

Potrebbero piacerti anche