Can't comment selection

2020-02-16 07:03发布

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

Do you have any idea why? Am I the only one having this issue?

Screenshot of the disabled command

EDIT: It seems to work again after restarting Xcode... Still looking from where it comes. It's a bit annoying...

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!

EDIT3: the proposed xpccachectl command to fix it doesn't exist on MacOS High Sierra.

15条回答
ゆ 、 Hurt°
2楼-- · 2020-02-16 07:06

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.

查看更多
你好瞎i
3楼-- · 2020-02-16 07:07

For me it was a little bit of CompSci 101:

Restart your computer

查看更多
看我几分像从前
4楼-- · 2020-02-16 07:09

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.

查看更多
疯言疯语
5楼-- · 2020-02-16 07:09
  1. Exit Xcode
  2. Type sudo /usr/libexec/xpccachectl in Terminal
  3. Restart Xcode
  4. Restart your Mac if needed

Source

查看更多
Anthone
6楼-- · 2020-02-16 07:11

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";
查看更多
三岁会撩人
7楼-- · 2020-02-16 07:12

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

查看更多
登录 后发表回答