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条回答
家丑人穷心不美
2楼-- · 2020-02-16 07:31

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.

查看更多
小情绪 Triste *
3楼-- · 2020-02-16 07:31

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.

查看更多
何必那么认真
4楼-- · 2020-02-16 07:31

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!

查看更多
登录 后发表回答