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
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.
Software Updatesmore updates
- Apple Remote Desktop updated with Yosemite support
- OS X Yosemite 10.10.2, iOS 8.1.3 updates now available
- Sports Illustrated 120 SPORTS channel comes to Apple TV
- Logic Pro X update brings AirDrop support, new effects, tools, and more
- Parallels Access 2.5 released, adds file manager, computer-to-computer remote access
- The Google Translate iOS app is about to get a lot smarter