14 Essential Xcode Tips, Tricks and Resources for iPhone Devs
Xcode is big. Apple’s Xcode Workspace Guide, a terse inventory of its features, is 116 pages. Xcode’s preference window has 13 sections, each with a dozen or more items. There are at least 206 keyboard shortcuts. I started counting menu items but gave up the ghost when I’d topped 300 items before finishing the third section.
Cutting Through The Clutter
We’ve collected a set of tips, resources, how-tos, tutorials and links ranging from newbie-to-expert to help you wring the maximum amount of productivity out of Xcode:
[Note: Apple changed their link-structure, so all of the links to Apple’s documentation are now broken. Anyone know of a “permalink” like approach to pointing to Apple documentation so I can fix this once and not have to redo again and again? Email [email protected]]
Workspace Tweaks
All-in-One Window Layout from Apple’s Xcode Workspace Guide – For many, Xcode’s default layout feels like a sea of windows. Xcode’s All-in-one layout, accessible under Preferences… > General, “provides a single project window in which you can perform all the tasks necessary for software development.” A Condensed layout style is also available.
Split Editor from Apple’s Xcode Workspace Guide – Miss multi-panel editing from your last editor? I’m looking at you, vim and emacs. Split the editor horizontally by clicking the button (located on the top-right of the editor pane) or with the keyboard shortcut command-“. Split the editor vertically with by prefixing the preceding with the Option key. Close either with .
Cocoa Programming for Mac OS X by Aaron Hillegass (Profile) suggests turning on Syntax-aware indenting under Preferences… > Indenting and always showing the console when running an app under Preferences… > Debugging > On Start: Show Console.
Keyboard and Mouse Shortcuts
The Xcode Tips & Tricks thread on Stack Overflow features, among other things, these Essential Keyboard and Mouse Shortcuts:
- Option-Command-Up: toggle betweeen .m and .h files
- Code completion: press tab to accept the current suggestion
- Command-double-click: jump to the .h definition of the symbol under the mouse
- Option-double-click: open the documentation for the symbol under the mouse
- Command-shift-D: open file quickly (similar to Command-t in TextMate)
Jeff Nouwen (Profile) reported, “After discovering ??E [which hides the details panel above the editor panel] and remembering ^1 [which brings up a quick jump to recent files], the All-In-One layout in Xcode is starting to really grow on me. Viva keyboard shortcuts!”
Colin Wheeler (Profile) has compiled a comprehensive list of a mind-boggling 206 Keyboard Shortcuts in PDF and PNG format.
Text Macros
55 C and ObjC Text Macros with Completion Prefixes from Apple’s Xcode Workspace Guide – Type the letter-a then escape and expand it to[[(class) alloc] init]. Type aa-escape for an array. 53 others to choose from.
Custom TextMate-Like Macros by Dylan Bruzenak (Profile) is a step-by-step tutorial to add your own macros and, if you prefer, make them more TextMate like.
Custom Project and File Templates
Custom Project Templates by Dylan Bruzenak (Profile) – Find yourself repeating the same configuration setup every time you create a new project? Create your own project template.
Similarly, Dylan has a post on Custom File Templates that demonstrates how to create new templates that will show up under New File menus.
User Scripts
User Scripts in Apple’s Xcode Workspace Guide – Perform programmatic manipulation of (selected) text in files.
Instance variable to synthesized property (an Xcode user script) by Matt Gallagher (Profile) – Xcode User Scripts aren’t intended to work on multiple files. In this post, Matt demonstrates scripting changes to both header and implementation files.
Xcode and Git
Shane Vitarana (Profile) shows how to create a .gitignore file for Xcode projects.
Marcus Zarra (Profile) wrote about making Git automatically inject the build number into the application bundle.
Something Missing?
Your favorite Xcode trick not listed? Add a comment! We can always run a second Xcode tweaks post (attributing tips to their authors).
Regarding the two involving git, I’ve improved upon both – in part, taking into account the very links you provided. The new .gitignore and new .gitattributes are slightly improved (why on earth is .DS_Store in there! Put it in your global file, dude. Don’t pollute your repositories with OS/application/machine/setup-specific .gitignore entries)
As for the git version number script, I provided a huge improvement to that as well: https://github.com/elliottcable/xcode-git-versioner
NSZombieEnabled!
When an object is dealloc’d and you send a message to it, the error is less than helpful. That’s where NSZombieEnabled comes in! It will keep the object around and raise an error when you try to send it a message. Great for debugging.
Put the line below in your ~/.gdbinit file and all your projects will use it automatically.
set env NSZombieEnabled=YES
I use many of the mentioned commands.
Other ones I use a lot:
– command-left (or right): navigate through file history
– command-shift-R: shows console
– command-zero: brings back to editor screen when I’m in debugging mode (all-in-one preference)
– command-/: toggle comments
Great post. Very nice tricks
Nice collection of tips!
Nice tips thanks.
Development question, that little lower case i button in some apps that opens settings. How do you create/enable/ and use it. What is it even called?
THANKS!
I was wondering where xcode actually keeps the user scripts.
Expected them in ~/Library/Application Support/Xcode
as that is the path apple recommends to purge when resetting Xcode.
They are not there.
Does anyone know?
An article at mactech.com suggests the path to be:
/Library/Application Support/Apple/Developer Tools/Scripts/10-User Scripts
And that’s the way it is for scripts NOT created in Xcode’s ‘Edit User Scripts’ panel.
The scripts created from within Xcode are squashed into a plist!
~/Users/luke/Library/Application Support/Developer/3.1/Xcode/XCUserScripts.plist
Thanks Apple, some more consistency would be appreciated!
Very nice post.
command- tilt
I use command- tilt to move between same group windows( Eg: if you have console, debugger, editor .. etc, if you want to move between those, you can user this) Not only for xcode, it works with normal windows, firefox, safari, textEdit…etc
thanks – nice tips, especially the run console automatically is going to save my life. I still can’t believe that when I get a crash, I need to type bt to get a backtrace – is there no option to automatically show the backtrace? Luckily I don’t use debuggers or I would be pretty miffed at the absence of a proper visual iPhone debugger.
The comparisons with TextMate are amusing – in the land of the blind, the one-eyed is king, I suppose. More appropriate would be to demand features like in Eclipse, IntelliJ, or Visual Studio – real IDEs which save an estimated 30% development time by automating many things.
Last not least, the saving grace for XCode, to me, is the ability to create user scripts. In Ruby, or as any other shell script.
I have a user script that automates properties, for example. I type the definition, then hit my shortcut and it fills in: The properties declaration (separate from the variables decl in the .h file), the synthesize and release statements in the right places in the .m file.
Erm I just see they do have a visual debugger.. I take it all back. Still don’t forgive the general 10-year-behindness when compared to Eclipse 😉
Heres a script I made to auto create your .gitignore and .gitattributes files… I hacked it together with a few other people’s stuff. Have fun!
https://github.com/tbarbe/Xcode-Git-User-Script
No warranties… I suck at most of this – so use at your own peril!