Most Popular in Apple
-
A fix for those "Pairing Record Missing" errors
-
Mac Hey, Sailor! Collection Lipstick Swatches
-
Apple receives regulatory approval for solar farm in North Carolina
-
Woz hired as technical advisor on Jobs biopic
-
Daily Update for May 18, 2012
-
How Much Is Zuckerberg Worth? [Live Infographic]
-
Class-action suit targets Apple for iCloud downtime
-
Yodlee Wants to Shake Up Finance, Introduce Alternate Credit Score
-
Mac Hey, Sailor! Powder Blush Swatches - Launch Away! & Fleet Fast
-
Being Open Could Close the Door on Android
Dev Juice: How do I autocomplete in Xcode 4?

Dear Dev Juice,
I just moved from Xcode 3 to Xcode 4. How can I make autocomplete give me a template? I type -(void)deal and the drop down pops up. tab just completes the dealloc word.
I want it to pop out the template for me. Space bar doesn't work, enter, escape, nothing anymore. I need to know how to make it dump the template
Tigerpaw

Dear Tigerpaw,
Xcode 4 offers a slightly different take on text macros. Code snippets are now the way to go.
The problem is that you're typing -(void) deal and expecting it to expand to the skeletal dealloc method. What you need to do is this. Go outside of any method and type de. No "- (void)". Immediately, Xcode will pop-up a completion menu and the first choice will be dealloc.

That's because you need use code snippets by name in Xcode 4, not by structure. You can find out the name of your snippet by using the Code Snippet Library browser.
Enter dea in the text field at the bottom of the browser. It returns just one match, "Objective-C dealloc Method". Hover over the selected item until a pop-up appears and then click Edit. Here you'll find the completion shortcut name. As you can see, the name here is "dealloc".

Creating your own custom snippets and naming them with shortcuts is just as easy. Select text in the Xcode code editor. Click and hold for a second in the selection and then drag it over to the library. It appears at the end of the library list and is named My Code Snippet by default.
Do the hover/pop-up/edit trick again to enter the edit mode above. Change the snippet's title, summary, and completion shortcut and click Done. Your new snippet will now be available for use using the shortcut you assigned.

Enter the first few characters, press return. Presto.

Should you want to add a placeholder into your new snippet, surround it with <# and #>, e.g.
int foo = <#value#>;
Xcode automagically converts this into a placeholder in the editor.

Dev Juice: How do I autocomplete in Xcode 4? originally appeared on TUAW - The Unofficial Apple Weblog on Tue, 05 Jul 2011 12:00:00 EST. Please see our terms for use of feeds.
More Stories in TUAW
- G-Technology G-Drive mobile: Rugged, pocket-sized, and fast
- MacStories looks at four years of the App Store
- Daily Update for May 18, 2012
- Motorola, RIM offer Apple a nano-SIM compromise
- Apple's iTunes Festival scheduled for September
- G5 Mac Pro receives Macquarium treatment
- G5 Mac "Pro" (sic) receives Macquarium treatment
- DropKey app encrypts Mac files, free through Sunday
- Apple assuming retail lease, plans to open new UK Apple Store
- Woz hired as technical advisor on Jobs biopic
Most Popular Stories
A fix for those "Pairing Record Missing" errors
Mac Hey, Sailor! Collection Lipstick Swatches
Apple receives regulatory approval for solar farm in North Carolina
Woz hired as technical advisor on Jobs biopic
Regular expression
Daily Update for May 18, 2012
How Much Is Zuckerberg Worth? [Live Infographic]
Class-action suit targets Apple for iCloud downtime
Yodlee Wants to Shake Up Finance, Introduce Alternate Credit Score
loginlog not registering failed logins