Xcode Tips and Tricks
Little tidbits to help you program on Mac OS X
These tips apply to Xcode versions 2.5 and earlier.
This page is a collection of tips and tricks for using the Xcode IDE efficiently to write your masterpiece for Mac OS X. All modern Chimoosoft software, and most other Mac software is written using Xcode which is provided free of charge from Apple along with all of their other development tools! These tools are bundled on the install CD with every new Mac and every copy of OS X, or you can download the latest version from the Apple Developer Connection web site after signing up for a free account. The page is a work in progress, so check back later for more or submit your own via our contact page.
Browsing Documentation
- Man Pages
- Man pages can be opened by choosing "Help->Open man page..." and browsed in a more convenient manner than on the command line.
- API Search
- When browsing the built in help through "Help->Documentation", try the "API Search" in addition to the "Full-Text Search"; they operate in quite different manners. For a quick lookup, API is more useful. If searching for an unknown document, full text is better.
- Wild Cards
- The usual * wildcard can be used when searching documentation.
- Search Operators
- Also try +, -, just like when searching Google.
- Jumping to Documentation
- While coding, you can right-click on a term and choose "Find Selected Text in Documentation" (full-text search) or "Find Selected Text in API Reference" (API only search) to jump right to it. Or, try ⌥ (option) double clicking on a term in your editor. Very handy.
- Font Size Xcode
- Under the Documentation tab of the Xcode preferences, you can set the minimum text size to be a bit larger so the documentation is readable.
- AppKiDo
- For another way to browse the Apple documentation, try the freeware program called AppKiDo which is reviewed here.
Coding
- Jumping to Definition
- An extremely handy tip - while coding, ⌘ (command) double click any term in your code to jump to its definition. For example, ⌘ double clicking on a method name will jump you to the definition of that method.
- From .h to .m and Back Again
- Press command-option-up-arrow to jump back and forth between your .m file and .h file. Also works for other languages.
- External Editors
- Some files such as plists are easier to view with editors other than Xcode. The default double click behavior can be edited in the "File Types" section of the Xcode preferences.
- Code Completion
- The code completion feature in Xcode called "Code Sense" works very well and will save you a lot of typing and syntax errors. Enable this through the "Code Sense" tab of the Xcode preferences, and make sure to keep your code sense index up to date after major changes (or when it behaves strangely) by using the "Rebuild Code Sense Index" button under the "Project->Edit Project Settings" menu item or by double clicking on your project icon.
- Split Panes
-
To compare two sections of code side by side, use the split pane button near the top right hand side of the editor window. The button below it will merge the panes back together again when you're done.
Debugging
- Alternate View
- Select "Debug->Toggle Debugger Layout" to rotate the panes. The layout with the variables on the bottom left may be easier to work with since the code editor is now much taller.
- Run to Here
- While stopped at a breakpoint, option-click in the gutter where breakpoints are normally set to set a temporary break point and continue code execution until the point where you clicked. This is much easier than having to manually set a breakpoint and then remove it when finished.
- Breakpoint Actions
- Breakpoint actions
are very powerful; rather than just stopping at a breakpoint, you can have the debugger log something, say it out loud, run a script, etc.. To add an action, double click on a breakpoint in the gutter, fold it out, and press the "+" button. Make sure to check the continue checkbox if you don't want the debugger to actually stop code execution. - Built-in Breakpoints
- Try right-clicking in the gutter where you want to add a breakpoint and looking at the options under the "Built-in Breakpoints" sub-menu. Handy for quick one-offs.
- Zombies
- To help debug premature deallocation problems, get info on your executable in Xcode and add the argument "NSZombieEnabled" with the value "YES" to receive more useful debugging messages in the console at runtime. This argument keeps objects from actually getting deallocated and instead just marks them as deallocated. Note that a similar Core Foundation (CF) argument must be used instead for some objects such as NSString.
- Localized Strings
- For problems with missing localized strings, enable "-NSShowNonLocalizedStrings YES" in the arguments for your executable.
Class Modeling
- Quick Model
- To quickly ascertain the relationship between a group of classes, select them and choose "Design->Class Model->Quick Model." This creates a temporary graphical model for your viewing pleasure.
- Persistent Model
- To create a longer lived class model which you can play with and save changes to (visual changes, not changes to the classes), choose "File->New File..." and then select the "Design->Class Model" file type. A window will appear which allows you to add as many classes to the model as you desire; more can be added later if you change your mind.
Fun Stuff
- Column Selection
- Holding down the option key while dragging allows you to perform a column based selection of text. Might be useful in limited circumstances.
