Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom code snippets to XCode 4? [duplicate]

If you show the Utilities pane on the far right of the XCode window, then select the "{ }" button, it shows code snippets that you can type the shortcut for, or drag and drop into your source code. How do you create your own?

like image 654
Jay Imerman Avatar asked Jul 22 '11 01:07

Jay Imerman


Video Answer


1 Answers

Although the documentation is very scant on this, I did find a blog post by Jason Brennan that describes step-by-step.

  1. Type in the code you want to create a snippet for.
  2. Highlight the code.
  3. Drag the highlighted code and drop it on the Snippet utility section.
  4. Click the snippet, a popup caption dialog will appear. Edit the title, description, and shortcut.

NOTE: You can use prompters denoted by <#prompterName#> that will give blue bubbles that you can tab to, and replace with "parameters" in your source. For example:

NSDictionary *<#varibleName#> = [[NSBundle mainBundle] infoDictionary];

NOTE: Depending on the language of the source code file you are editing, your new snippet will default to be in that language. In this way, snippets are selectively used for Swift or Objective-C depending on your context.

NOTE: If you attempt to drag highlighted text, and it unselects and starts a new selection instead, try to start your drag action in the whitespace off to the right of your selected text.

Also, to delete your snippets, click to highlight in the snippet library, and press the "Delete" key.

like image 103
Jay Imerman Avatar answered Oct 31 '22 05:10

Jay Imerman