Can't comment selection

XcodeComments

Xcode 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?

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.

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)

Conflicting Shortcut

Solution 5 - Xcode

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

Source

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.

  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

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:

  1. Type sudo /usr/libexec/xpccachectl in Terminal, then reboot.
  2. 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!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTullebView Question on Stackoverflow
Solution 1 - Xcodejoe_04_04View Answer on Stackoverflow
Solution 2 - Xcodedustin hullettView Answer on Stackoverflow
Solution 3 - XcodeBen StahlView Answer on Stackoverflow
Solution 4 - XcodeDanielView Answer on Stackoverflow
Solution 5 - XcodeTullebView Answer on Stackoverflow
Solution 6 - XcodeeonilView Answer on Stackoverflow
Solution 7 - XcodedfruitView Answer on Stackoverflow
Solution 8 - XcodeJim LeaskView Answer on Stackoverflow
Solution 9 - XcodeRic SantosView Answer on Stackoverflow
Solution 10 - XcodeRubens SendayView Answer on Stackoverflow
Solution 11 - XcodeAshuView Answer on Stackoverflow
Solution 12 - XcodeJacksonView Answer on Stackoverflow
Solution 13 - XcodeThe App LadyView Answer on Stackoverflow
Solution 14 - XcodebugloafView Answer on Stackoverflow
Solution 15 - XcodeJames LTView Answer on Stackoverflow