Information Technology Reference
In-Depth Information
Creating a new snippet
Creating a new snippet is easy after you understand how to do it, but until you do, the process is unintuitive.
Creating a snippet with drag and drop
It's unexpectedly easy to miss this feature, and it has some hidden subtleties. To create a snippet, drag-highlight
the code you want to include, click the highlighted area, and hold down the mouse button until the cursor
changes to a pointer . If you don't hold down the mouse button, Xcode assumes you're attempting to highlight
a different section of code.
Drag the snippet to the Code Snippet Library and release it anywhere. The snippet is added as the last item in
the User library with a default name—My Code Snippet.
In the first release of Xcode 4, you can only add a snippet when the Code Snippet Library or User items are se-
lected. This means that when the snippet list is filtered to show iOS or OS X snippets, adding a snippet seems
to have no effect. In fact, the snippet is added to the User list—which is invisible.
Similarly, you also can't see or insert user snippets when viewing iOS or OS X items. You can only use them
when you select the User list or the unfiltered Code Snippet Library list.
This may change in future releases—the current implementation is inconvenient for developers who want to
create and use snippets on either or both platforms.
Once you have created a snippet, you can edit the name and add optional symbol placeholders, as described
below.
Search WWH ::




Custom Search