Can't comment selection
XcodeCommentsXcode Problem Overview
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?
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.
Xcode Solutions
Solution 1 - Xcode
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.
Solution 2 - Xcode
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.
Solution 3 - Xcode
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.
Solution 4 - Xcode
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)
Solution 5 - Xcode
- Exit Xcode
- Type
sudo /usr/libexec/xpccachectl
in Terminal - Restart Xcode
- Restart your Mac if needed
Solution 6 - Xcode
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.
- 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.
Now it works.
Solution 7 - Xcode
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.
Solution 8 - Xcode
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";
Solution 9 - Xcode
For me it was a little bit of CompSci 101:
> Restart your computer
Solution 10 - Xcode
I did as Joe_04_04. Renamed de Xcode APP to anything else and back to original name
Solution 11 - Xcode
Fix Xcode 8 Comment/UnComment menus: "sudo /usr/libexec/xpccachectl
" then reboot.
This works for me. Good Luck.
Solution 12 - Xcode
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:
- Type
sudo /usr/libexec/xpccachectl
in Terminal, then reboot. - rename the Xcode 8.2.1 to
Xcode8
,restart Xcode8, now it works!
Solution 13 - Xcode
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.
Solution 14 - Xcode
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.
Solution 15 - Xcode
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!