87

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.

Tulleb
  • 8,919
  • 8
  • 27
  • 55

15 Answers15

90

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.

Pang
  • 9,564
  • 146
  • 81
  • 122
JosephTLyons
  • 2,075
  • 16
  • 39
  • 5
    `/usr/libexec/xpccachectl` and reboot didn't work. Renaming Xcode.app to Ycode.app and launching it worked for me too. After it worked, I renamed app back to Xcode and it still worked. An interesting note, iTunes just updated yesterday to V12.5.3 and the comment selection stopped working. Running `macOS 10.12.1` `Xcode 8.1 (8B62)` – One In a Million Apps Nov 15 '16 at 17:54
  • 1
    This issue occurs on my Mac from time to time and every time I have to try out a different method to solve it... This time yours worked well but last time I used this one http://stackoverflow.com/a/39936649/1203713 – Sn0wfreeze Jan 31 '17 at 19:13
  • 3
    Works. Absolutely ridiculous Apple. – Oliver Pearmain Jul 03 '17 at 12:45
  • 2
    I don't want to know how many things you tried before figuring this out… but thank you! – devios1 Jul 26 '17 at 16:26
  • 2
    This happens to me on a weekly basis, renaming works but is so unnecessary. Come on Apple surely your devs are annoyed by this too? Sort it out! – Jack Dewhurst Jul 27 '17 at 10:01
  • 1
    Woah, iTunes just updated for me, and it stopped working (2017..!) – Leonard Pauli Sep 16 '17 at 19:04
  • @joe_04_04 jupp :) (Xcode 8.2.1... well, I do have an old version...) – Leonard Pauli Sep 17 '17 at 13:56
  • worked with Xcode 9.3! :) Thank you Xcode is a – Mo Farhand Nov 15 '18 at 15:00
23

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.

Martin Koles
  • 5,177
  • 8
  • 39
  • 59
dustin hullett
  • 231
  • 2
  • 2
19

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.

Ben Stahl
  • 1,139
  • 11
  • 11
  • This is still not working for me in Beta 5 as well. I restarted my computer and restarted Xcode several times. Additionally, when played around with "Command+[" and "Command + ]", they stopped working as well. – josephap Aug 12 '16 at 20:09
  • 1
    Still not working in beta 6 (on 3 different machines). I submitted a bug report, Apple marked it as a duplicate, so hopefully they are working on it. I'm just hoping they didn't mark it as a duplicate of the previous bug that they thought (and said) they fixed in beta 5, but didn't. Open Radar: https://openradar.appspot.com/radar?id=4976322216460288 – Ben Stahl Aug 18 '16 at 23:49
  • Update: The bug # they gave me for the duplicate is NOT the same # as listed above (the bug "fixed" in beta 5). So hopefully this means they know it was not in fact fixed for everyone and opened a new bug. – Ben Stahl Aug 18 '16 at 23:57
  • For me with beta 6: on a Macbook Pro it works OK, on a Mac Mini it doesn't work. – user3717478 Aug 22 '16 at 10:08
  • 11
    Still not fixed, but some dude on Twitter found a workaround that works for me. `sudo /usr/libexec/xpccachectl` then reboot. https://twitter.com/kolpanic/status/763323546814844928 – Ben Stahl Aug 26 '16 at 20:33
  • 9
    The problem still occurs on official XCode 8 release. The twitter fix worked for me too... but a few days later it reverted to the same problem. So it's apparently only a temporary fix that needs to be reapplied. Very annoying as it affects such a key productivity issue as commenting blocks of code, rather than just a line at a time. – gpdawson Sep 15 '16 at 00:05
  • Had the same issue, restart Mac mixed it. – App07 Sep 19 '16 at 20:38
  • Have the issue and restarting didn't fix it for XCode 8 and 10.11.6 – LyricalPanda Sep 19 '16 at 23:28
  • Same issue on El Capitan, Xcode 8 release version. `xpccachectl` fixed it (for now). This is absolutely ridiculous. – Nikolay Spassov Oct 02 '16 at 10:01
  • 5
    It seems that the `xpccachectl` spell does not work if XCode 8.1 beta is also installed. What a mess. – spassas Oct 03 '16 at 09:29
  • @spassas I renamed Xcode beta app to "Xcode81.app", quit the Xcodes, then run the command in terminal and it worked finally, unless you start the beta, then need to rename again and repeat. – Artur Oct 05 '16 at 14:11
  • 1
    This just happened to me on XCode Version 8.1 (8B62). Apparently still not resolved! Moving XCode into another folder, running `sudo /usr/libexec/xpccachectl` as others have suggested, and then moving it back got it back to working. – Troy Nov 03 '16 at 06:37
  • I followed 5-8 methods to re-solve this problem in my x-code 8.x(EI- Captain OS) but still facing the same problem. is it really enabled by Apple? – dahiya_boy Jan 09 '17 at 05:23
  • Same here. Tried moving and renaming it but still nothing. WTF. It's an industry standard for f*cks sake ! – sasklacz Jan 18 '17 at 10:26
  • 1
    Still happening on Version 8.2 (8C38). Restarting Xcode didn't help either. It comes and goes. :( – Genki Jan 26 '17 at 19:39
  • This is among the most annoying bugs that a developer tool can have. I am ok with not having good suggestions because of broken index but I hate commenting each line in a file one by one while debugging. NOTE: I have tried all solutions available everywhere. This bug is not resolved in Version 8.2.1 (8C1002). I follow some steps on the threads and the comment shortcut starts working but after few mins it again stops working. I hate restarting my work environment again and again x-( – Yogesh Maheshwari Apr 19 '17 at 23:41
13

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

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
Daniel
  • 131
  • 1
  • 2
  • Xcode usually overrides this command, but I got exactly this behaviour once this bug shoed up. Renaming Xcode worked for me. – Andy Jul 25 '17 at 10:21
  • Thank you! Have been working (about 4 months now) without being able to comment out selection!! You made my day better :) – troligtvis Aug 01 '17 at 10:32
  • Couldn't manage to fix with the other solutions, this one works perfectly! – SFWdc Sep 28 '17 at 12:30
10
  1. Exit Xcode
  2. Type sudo /usr/libexec/xpccachectl in Terminal
  3. Restart Xcode
  4. Restart your Mac if needed

Source

Tulleb
  • 8,919
  • 8
  • 27
  • 55
3

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

eonil
  • 83,476
  • 81
  • 317
  • 516
  • How can I set it back to `Command + /` please? On my keyboard I need to use `Shift` key to do it so it set the shortcut to `Shift + Command + /`... Not working better with the `Caps Lock` activated, already tried. – Tulleb Nov 08 '16 at 12:53
  • 2
    Didn't work for me unfortunately. Still no comment hotkeys :| – allocate Nov 17 '16 at 16:33
3

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.

dfruit
  • 111
  • 4
  • 1
    Bingo! The /* form of the "comment" doesn't even have to be a real comment. In my case it is part of a NSPredicate format. /* shows up as part of the string data, but the existence of this breaks the comments. – Jim Leask Feb 23 '17 at 19:10
  • This was the cause of my problem too. I replaced the comments with //, rebooted my computer and the shortcut was back! – CallumOz May 17 '17 at 07:59
2

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";
Community
  • 1
  • 1
Jim Leask
  • 6,159
  • 5
  • 21
  • 31
2

For me it was a little bit of CompSci 101:

Restart your computer

Ric Santos
  • 15,419
  • 6
  • 50
  • 75
1

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

1

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

This works for me. Good Luck.

Ashu
  • 3,373
  • 38
  • 34
1

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!

Jackson
  • 19
  • 1
0

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.

0

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.

bugloaf
  • 2,890
  • 3
  • 30
  • 49
0

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!

James LT
  • 733
  • 2
  • 12
  • 23