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

Solution 1:

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.

Solution 2:

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...

Solution 3:

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

Solution 4:

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.