xcode 无法评论选择
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38847530/
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
Can't comment selection
提问by Tulleb
Sometimes, it seems I can't comment my code with the usual shortcut (command
+ /
) under Xcode 8 Beta 4. The option is disabled in the menu (screenshot below).
有时,我似乎无法使用Xcode 8 Beta 4 下的常用快捷方式 ( command
+ /
)注释我的代码。该选项在菜单中被禁用(下面的屏幕截图)。
Do you have any idea why? Am I the only one having this issue?
你知道为什么吗?只有我有这个问题吗?
EDIT: It seems to work again after restarting Xcode... Still looking from where it comes. It's a bit annoying...
编辑:它似乎在重新启动 Xcode 后又可以工作了......仍然从它来的地方看。有点烦...
EDIT2: It still occurs on Xcode 8.1. Maybe because I have 2 versions of Xcode installed (normal and beta)? Can't fix it anymore with a simple restart!
EDIT2:它仍然发生在 Xcode 8.1 上。也许是因为我安装了 2 个版本的 Xcode(普通版和测试版)?无法通过简单的重新启动来修复它!
EDIT3: the proposed xpccachectl
command to fix it doesn't exist on MacOS High Sierra.
EDIT3:建议的xpccachectl
修复命令在 MacOS High Sierra 上不存在。
采纳答案by Tulleb
回答by joe_04_04
Try this. Out of all the other suggestions, this was the only one that worked for me.
尝试这个。在所有其他建议中,这是唯一对我有用的建议。
Go to your applications folder and rename Xcode to whatever you want, then open the Xcode. Check to see if the comment selection now works, if so, you can go back and rename Xcode to its default name. If not, rename Xcode back to its original name anyway, and continue searching for another solution.
转到您的应用程序文件夹并将 Xcode 重命名为您想要的任何名称,然后打开 Xcode。检查注释选择现在是否有效,如果有效,您可以返回并将 Xcode 重命名为其默认名称。如果没有,无论如何将 Xcode 重命名回其原始名称,并继续寻找其他解决方案。
This worked perfectly for me.
这对我来说非常有效。
回答by dustin hullett
None of the workarounds worked for me after installing xcode 8.1 beta. I finally found that moving the Xcode beta out of the applications folder into a different location (desktop is where i put mine) then running sudo usr/libexec/xpccachectl
fixed the issues i was having.
安装 xcode 8.1 测试版后,没有一种解决方法对我有用。我终于发现将 Xcode 测试版从应用程序文件夹中移到不同的位置(桌面是我放置我的位置)然后运行sudo usr/libexec/xpccachectl
修复了我遇到的问题。
回答by Ben Stahl
This is a known bug in Xcode 8 beta-4 (according to Apple, on "some systems", without specifying which ones).
这是 Xcode 8 beta-4 中的一个已知错误(根据 Apple 的说法,在“某些系统”上,没有指定哪些系统)。
The good news is, according to Apple they've fixed this in beta-5. From the release notes:
好消息是,根据 Apple 的说法,他们已经在 beta-5 中修复了这个问题。从发行说明:
Resolved in Xcode 8 beta 5 – IDE
The Editor's Comment/Uncomment Selection command is functional when enabled. (27524523)
在 Xcode 8 beta 5 – IDE 中解决
编辑器的注释/取消注释选择命令在启用时起作用。(27524523)
The bad news is, it's still not working for me in beta-5, even after rebooting. And for the life of me, I can't figure out what they mean by "when enabled". Since when do you have to "enable" comment/uncomment, and how would you go about doing that?
坏消息是,即使在重新启动后,它在 beta-5 中仍然对我不起作用。对于我的生活,我无法弄清楚“启用时”是什么意思。从什么时候开始你必须“启用”评论/取消评论,你会怎么做?
I'm on a Mac Pro cylinder running El Capitan 10.11.6, editing Swift 2.3 code.
我在运行 El Capitan 10.11.6 的 Mac Pro 圆柱体上,编辑 Swift 2.3 代码。
回答by Daniel
回答by dfruit
My situation is a bit different(stupid?): I found I can't comment any line from a particular part of a particular file. I tried all the methods above with Xcode 8.1 and Xcode 8.2, but got no luck. Finally I found it was caused by a comment trick like below,
我的情况有点不同(愚蠢?):我发现我无法评论特定文件特定部分的任何行。我在 Xcode 8.1 和 Xcode 8.2 上尝试了上述所有方法,但没有成功。最后我发现它是由下面的评论技巧引起的,
1 /*
2 code
3 //*/
4 code
In Xcode, you can't comment line 2 with Cmd+/ because it has been commented already by /**/, which is fine. However, you can't even comment line 4 with Cmd+/, as Xcode may think it's still in a /* */ block, but it's actually not. If I remove // from line 3, then commenting line 4 works fine.
在 Xcode 中,你不能用 Cmd+/ 注释第 2 行,因为它已经被 /**/ 注释了,这很好。但是,您甚至不能用 Cmd+/ 注释第 4 行,因为 Xcode 可能认为它仍在 /* */ 块中,但实际上并非如此。如果我从第 3 行中删除 //,则注释第 4 行工作正常。
回答by Eonil
It still happens in Xcode 8.1 which was installed from Mac App Store.
它仍然发生在从 Mac App Store 安装的 Xcode 8.1 中。
I tried sudo usr/libexec/xpccachectl
, but no luck.
我试过了sudo usr/libexec/xpccachectl
,但没有运气。
I could solve this be reassigning shortcut keys again.
我可以通过再次重新分配快捷键来解决这个问题。
- Go to Preference -> Key Bindings
- Set some random shortcut key on
Structure -> Comment Selection
menu. You don't have to change all of them. One is enough. - Set it back to
Command + /
again.
- 转到首选项 -> 键绑定
- 在
Structure -> Comment Selection
菜单上设置一些随机快捷键。您不必更改所有这些。一个就够了。 - 重新设置回来
Command + /
。
Now it works.
现在它起作用了。
回答by Jim Leask
It seems that if you have nested /* anywhere in your code it breaks the commenting from then on. Others have reportedthat it happens with nested block comments. However if you have nested /* anywhere, including a string it will fail.
似乎如果您在代码中的任何位置嵌套了 /* ,它就会从那时起破坏注释。其他人报告说它发生在嵌套块注释中。但是,如果您将 /* 嵌套在任何地方,包括一个字符串,它将失败。
Note the following bit of code is working with path characters /
and wildcards *
that together make /*
. Anything after this line and commenting out doesn't work in XCode.
请注意,以下代码将使用路径字符/
和通配符*
,这些字符和通配符共同构成/*
. 此行之后的任何内容和注释在 XCode 中都不起作用。
int foo = "this line can be commented out";
predicate = [NSPredicate predicateWithFormat:@"(cachedAudioDataURL like '*/Library/Private*/*')) AND (NOT (cachedAudioDataURL like '*/Documents/*'))"];
int bar = "broken - can't be commented out";
回答by Ric Santos
For me it was a little bit of CompSci 101:
对我来说,它有点像 CompSci 101:
Restart your computer
重启你的电脑
回答by Ashu
Fix Xcode 8 Comment/UnComment menus: "sudo /usr/libexec/xpccachectl
" then reboot.
修复 Xcode 8 注释/取消注释菜单:“ sudo /usr/libexec/xpccachectl
”然后重新启动。
This works for me. Good Luck.
这对我有用。祝你好运。