无法评论选择

有时候,我似乎不能用 Xcode 8 Beta 4下常用的快捷方式(command + /)注释我的代码。该选项在菜单中被禁用(截图如下)。

你知道为什么吗? 只有我有这个问题吗?

Screenshot of the disabled command

编辑: 在重新启动 Xcode 之后,它似乎又能工作了... ... 仍然在寻找它的来源。这有点烦人... ..。

编辑2: 它仍然发生在 Xcode 8.1上。也许是因为我安装了2个版本的 Xcode (普通版和 beta 版) ?只要重新启动就无法修复了!

编辑3: 在 MacOSHighSierra 上不存在修复它的 xpccachectl命令。

27845 次浏览

This is a known bug in Xcode 8 beta-4 (according to Apple, on "some systems", without specifying which ones).

The good news is, according to Apple they've fixed this in beta-5. From the release notes:

Resolved in Xcode 8 beta 5 – IDE

The Editor’s Comment/Uncomment Selection command is functional when enabled. (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?

I'm on a Mac Pro cylinder running El Capitan 10.11.6, editing Swift 2.3 code.

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.

It still happens in Xcode 8.1 which was installed from Mac App Store.

I tried sudo usr/libexec/xpccachectl, but no luck.

I could solve this be reassigning shortcut keys again.

  1. Go to Preference -> Key Bindings
  2. Set some random shortcut key on Structure -> Comment Selection menu. You don't have to change all of them. One is enough.
  3. Set it back to Command + / again.

Now it works.

enter image description here

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.

This worked perfectly for me.

On a German Macintosh Computer, there is a System keyboard shortcut overriding the Xcode comment section shortcut.

Simply deactivate the Hilfemenü anzeigen shortcut. (show help)

Conflicting Shortcut

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,

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.

I did as Joe_04_04. Renamed de Xcode APP to anything else and back to original name

It seems that if you have nested /* anywhere in your code it breaks the commenting from then on. Others have reported that 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.

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";

Fix Xcode 8 Comment/UnComment menus: "sudo /usr/libexec/xpccachectl" then reboot.

This works for me. Good Luck.

I just experienced this same issue for the first time (I've been using various versions of Xcode for over a year, maybe two).

After reviewing these threads, I noticed that my MacBook Pro had a pending update and could not install the update because Xcode was open. I closed/quit Xcode, installed the update, forced quit all open apps, restarted my laptop and the issue was resolved.

  1. Exit Xcode
  2. Type sudo /usr/libexec/xpccachectl in Terminal
  3. Restart Xcode
  4. Restart your Mac if needed

Source

This bug also happens on Xcode 8.2.1 (8C1002) of macOS 10.12.3 (16D32). And there is another Xcode 7.3, which is fine, also installed on my machine.

I find two solutions:
1. Type sudo /usr/libexec/xpccachectl in Terminal, then reboot.
2. rename the Xcode 8.2.1 to Xcode8,restart Xcode8, now it works!

This still (May 2017) happens to me occasionally in Xcode 8.3.2. Quitting Xcode is not enough to clear it up. Logging out and logging back in fixed it for me. I did not have to run a command line tool or reboot.

For me it was a little bit of CompSci 101:

Restart your computer

Not to downplay the discussion above, but I tried all the solutions proposed above and all failed. Finally I updated Xcode to the latest Version 9.3 (2018) and everything works now!