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?
-
would recommend using google prior to postingMax MacLeod– Max MacLeod2013-05-22 15:02:32 +00:00Commented May 22, 2013 at 15:02
-
Max, my point here was to log the Q&A in Stack Overflow, since that is a much better reference than Google for technical things. Thanks for reading and commenting!Jay Imerman– Jay Imerman2013-05-23 20:46:40 +00:00Commented May 23, 2013 at 20:46
-
You can use Snippets snippets.me. Check out this demo youtube.com/watch?v=il4kE4diy0kVladimir Prudnikov– Vladimir Prudnikov2013-06-25 18:38:12 +00:00Commented Jun 25, 2013 at 18:38
2 Answers
Although the documentation is very scant on this, I did find a blog post by Jason Brennan that describes step-by-step.
- Type in the code you want to create a snippet for.
- Highlight the code.
- Drag the highlighted code and drop it on the Snippet utility section.
- 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.
10 Comments
Just highlight your snippet and drag it into the snippets box.