Xcode Command-Slash 注释快捷方式仅在某些情况下有效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26631840/
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-08 18:01:56  来源:igfitidea点击:

Xcode Command-Slash Shortcut to Comment Only Works Sometimes

xcodecommentskeyboard-shortcuts

提问by Stonz2

I'm having issues with Xcode being quite unreliable when using the keyboard shortcut to comment or uncomment code ?+/. I can't seem to find a real pattern as to when it breaks, but it usually happens after building and running my code on the simulator. It will not work again until I edit something in any one of my code files. Even if I switch to another file in the main view, commenting via shortcut does not work. Other keyboard shortcuts, such as indenting ?+[continue to work just fine.

在使用键盘快捷键注释或取消注释代码?+时,我遇到了 Xcode 非常不可靠的问题/。我似乎无法找到关于何时中断的真正模式,但通常在模拟器上构建和运行我的代码之后发生。在我编辑任何一个代码文件中的内容之前,它不会再次工作。即使我在主视图中切换到另一个文件,通过快捷方式评论也不起作用。其他键盘快捷键,例如缩进?+[继续正常工作。

Do other people have this issue, and if so, have you found a solution? I know it seems like a small complaint, but when running and then quickly trying to comment out a block of code to check the effect, it's a bit of an inconvenience.

其他人是否有此问题,如果有,您是否找到了解决方案?我知道这似乎是一个小小的抱怨,但是当运行时然后快速尝试注释掉一段代码以检查效果时,这有点不方便。

I am using Xcode 6.1 (6A1052d) on OXS Yosemite 10.10 (14A389) and developing in Objective-C for iOS if that matters.

我在 OXS Yosemite 10.10 (14A389) 上使用 Xcode 6.1 (6A1052d) 并在 iOS 的 Objective-C 中开发,如果这很重要的话。

回答by CryingHippo

For an Xcode 8, solution is

对于 Xcode 8,解决方案是

sudo /usr/libexec/xpccachectl

and restart your computer.

并重新启动计算机。

回答by atulkhatri

Hit ?+]once and then ?+/will start working again.

点击?+]一次,然后?+/将再次开始工作。

You can hit ?+[to undo the indentation effect.

您可以点击?+[取消缩进效果。

Update:

更新:

Please note- This solution was provided prior to Xcode 8 launch so it may not work for everyone. If you are still facing problem, kindly refer to @CryingHippo's answerinstead of downvoting.

请注意 - 此解决方案是在 Xcode 8 发布之前提供的,因此可能不适用于所有人。如果您仍然遇到问题,请参考@CryingHippo 的回答,而不是投反对票

回答by Matt

I have done this numerous times with Xcode 8. Latest being Xcode 10.1 where I would just quit Xcode and go to Applications and rename Xcode to something else, e.g. Xcode 2, launch it, quit again and rename back. It starts working after that. No Mac restart or Terminal commands required.

我已经用 Xcode 8 多次这样做了。最新的是 Xcode 10.1,我会退出 Xcode 并转到应用程序并将 Xcode 重命名为其他内容,例如 Xcode 2,启动它,再次退出并重命名。在那之后它开始工作。无需重新启动 Mac 或终端命令。

It still works as of Xcode 10.1. I cannot believe Apple still hasn't fixed it properly.

它从 Xcode 10.1 开始仍然有效。我不敢相信 Apple 仍然没有正确修复它。

回答by Oscar Hierro

None of the above solutions worked for me with Xcode 8.0 (final). If you also have Xcode 8.1 beta installed like I do, try this: simply rename /Applications/Xcode-beta.app to something else, then restart Xcode 8. Oddly enough, that did the trick.

上述解决方案都不适用于 Xcode 8.0(最终版)。如果您也像我一样安装了 Xcode 8.1 beta,请尝试以下操作:只需将 /Applications/Xcode-beta.app 重命名为其他名称,然后重新启动 Xcode 8。奇怪的是,这确实成功了。

回答by Kqtr

Oscahie's answer actually works for non-beta versions of Xcode as well. Here are the steps to follow, based on Sam's comment:

Oscahie 的答案实际上也适用于非测试版的 Xcode。根据 Sam 的评论,以下是要遵循的步骤:

  1. Close Xcode
  2. In the Application folder, rename Xcode.app (or similar) to Xcode2.app. You might need to type in your password.
  3. Open Xcode, then close it.
  4. Rename Xcode2.app back to what it was before.
  5. (Optional) Spend 5 minutes wondering why this worked.
  1. 关闭 Xcode
  2. 在 Application 文件夹中,将 Xcode.app(或类似名称)重命名为 Xcode2.app。您可能需要输入密码。
  3. 打开Xcode,然后关闭它。
  4. 将 Xcode2.app 重命名为之前的名称。
  5. (可选)花 5 分钟想知道为什么会这样。

No need to reboot!

无需重启!

回答by user1366265

I didn't have to do any of the above. A simple reboot fixed it.

我不必执行上述任何操作。一个简单的重启修复了它。

回答by schinj

A simple workaround works good for me with following steps:

通过以下步骤,一个简单的解决方法对我很有用:

  1. Comment any line i.e. simply add "//" in front of a line.
  2. Press Command + "/" and it starts working.
  1. 注释任何行,即在一行前简单地添加“//”。
  2. 按 Command + "/" 并开始工作。

It might help someone.

它可能会帮助某人。

回答by Harold

In my code I had this sequence:
/*" BLABLA MY COMMENTS */
All the code under this was not "commentable".

在我的代码中,我有这个序列:
/*" BLABLA MY COMMENTS */
此下的所有代码都不是“可评论的”。

Removed the " and it was ok !

删除了“,没关系!

Hope it helps!

希望能帮助到你!

回答by Ohmy

I am using Xcode 8.1 (not beta) and I had the same problem, not able to cmd+\ to comment. Restart Xcode not working for me but RESTART my Mac SOLVED the problem without a need to remove cache.

我正在使用 Xcode 8.1(非测试版)并且我遇到了同样的问题,无法使用 cmd+\ 进行评论。重新启动 Xcode 对我不起作用,但重新启动我的 Mac 解决了问题,而无需删除缓存。

回答by Christian Schuster

I just had the same issue after setting up a new Mac with Xcode 10.1 using the German keyboard layout.

在使用德语键盘布局使用 Xcode 10.1 设置新 Mac 后,我遇到了同样的问题。

The solution was to disable the Keyboard shortcut in system settings for the help menu.

解决方案是在帮助菜单的系统设置中禁用键盘快捷键。

System settings > Keyboard > Shortcuts > App shortcuts.

系统设置 > 键盘 > 快捷方式 > 应用程序快捷方式。

There was a shortcut for all apps to show the help menu. If you have that, click the checkbox to disable it

所有应用程序都有一个快捷方式来显示帮助菜单。如果有,请单击复选框以禁用它

Screenshot of Keyboard shortcuts in Mac system preferences

Mac 系统偏好设置中的键盘快捷键屏幕截图