Can't drag (to make code snippet) in Xcode

When I follow all the instructions (including apple's video) to drag text to create a code snippet in xcode, I get a different system behavior: all I see is the selection ibeam... I can't drag. It just ends up selecting text again. Am i missing some obvious Apple-ism? Thanks

9184 次浏览

Yes, I ran into the same problem, and Apple-ism seems to be a good term for this issue :)

It works this way:

  • Select (or highlight) the code your want to turn into a snippet
  • EDIT: Click and hold (do not drag!) on any part of the selected text for a short moment (like 2 seconds, sometimes 8 seconds)
  • EDIT: The mouse cursor will change icon (not on El Capitan).
  • Now you can drag the code over the snippets library, where a green + icon will appear. EDIT: On El Capitan the green icon does not appear, but the frame of the code snippets window will become thinner.

This happened to me as well. The given solution didn't work but still needed to create snippets. This is a workaround although not the best option, it works.

  1. From Xcode, select the snippet window, and leave it selected.
  2. Open a text editor app.
  3. From Xcode, select and copy the code you want to use to create your snippet.
  4. Paste it into your text editor and then select all of it.
  5. Now drag&drop normally from the text editor into the snippets window in Xcode.

As said, not the best option but it works.

(Note for Xcode 8.1) Sometimes selecting the text and maintain the mouse button clicked for 3..8 seconds the cursor turns into an arrow and it's possible to D&D. Too bad it only works sometimes...

I've run into this problem with Xcode 7.2 on Mac OS X 10.11.2 (El Capitan). Click and hold on the selection and the cursor never changes from the I-beam to the arrow for dragging.

Although MLBDG's answer is a usable workaround, I found that quitting and restarting Xcode fixed the problem. This might not work for everyone, but it's worth a try if you're having difficulty.

On High Sierra 10.13.3 and XCode 9 I faced the same problem. The decision that works for me is selecting code on a blank space before the first symbol and then dragging it to the snippets library.

Important: you need to drag only from the blank space (look at the screenshot below). Otherwise you will reselect your code again.

The cursor changes only when you start dragging, so don't be confused and don't wait until it changes.

enter image description here

  1. just highlight your text
  2. copy in filter text field that u can see on your bottom of snippet library
  3. paste the text
  4. now select the text and drag from there to snippet library