无法在 Xcode 中拖动(制作代码片段)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6206380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:10:49  来源:igfitidea点击:

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

xcodecode-snippets

提问by Hyman Bellis

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

当我按照所有说明(包括苹果的视频)拖动文本以在 xcode 中创建代码片段时,我得到了不同的系统行为:我看到的只是选择 ibeam...我无法拖动。它最终会再次选择文本。我错过了一些明显的苹果主义吗?谢谢

回答by brainray

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

是的,我遇到了同样的问题,Apple-ism 似乎是这个问题的一个好词:)

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.
  • 选择(或突出显示)您想要变成片段的代码
  • 编辑:在选定文本的任何部分单击并按住(不要拖动!)片刻(例如 2 秒,有时是 8 秒)
  • 编辑:鼠标光标将更改图标(不在 El Capitan 上)。
  • 现在您可以将代码拖到代码段库上,那里会出现一个绿色的 + 图标。编辑:在 El Capitan 上,绿色图标不会出现,但代码片段窗口的框架会变薄。

回答by MLBDG

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.
  1. 在 Xcode 中,选择代码片段窗口,并保持选中状态。
  2. 打开文本编辑器应用程序。
  3. 在 Xcode 中,选择并复制要用于创建代码段的代码。
  4. 将其粘贴到您的文本编辑器中,然后选择所有内容。
  5. 现在从文本编辑器中正常拖放到 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...

(Xcode 8.1 的注意事项)有时选择文本并保持单击鼠标按钮 3..8 秒,光标会变成箭头,并且可以进行 D&D。太糟糕了,它只是有时有效......

回答by joliejuly

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.

在 High Sierra 10.13.3 和 XCode 9 上,我遇到了同样的问题。对我有用的决定是在第一个符号之前的空白处选择代码,然后将其拖到片段库中。

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

在此处输入图片说明

回答by rob mayoff

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.

我在 Mac OS X 10.11.2 (El Capitan) 上使用 Xcode 7.2 遇到了这个问题。单击并按住所选内容,光标永远不会从 I 型梁变为用于拖动的箭头。

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.

尽管 MLBDG 的答案是一个可用的解决方法,但我发现退出并重新启动 Xcode 解决了该问题。这可能并不适合所有人,但如果您遇到困难,值得一试。

回答by Ankita Panchal

  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
  1. 只需突出显示您的文字
  2. 复制您可以在代码段库底部看到的过滤器文本字段
  3. 粘贴文本
  4. 现在选择文本并从那里拖动到片段库