Can't comment selection

后端 未结 15 1220
暖寄归人
暖寄归人 2020-12-22 22:19

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 (screen

相关标签:
15条回答
  • 2020-12-22 22:53

    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.

    0 讨论(0)
  • 2020-12-22 22:53

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

    This works for me. Good Luck.

    0 讨论(0)
  • 2020-12-22 22:54

    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";
    
    0 讨论(0)
  • 2020-12-22 22:55

    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.

    0 讨论(0)
  • 2020-12-22 23:01
    1. Exit Xcode
    2. Type sudo /usr/libexec/xpccachectl in Terminal
    3. Restart Xcode
    4. Restart your Mac if needed

    Source

    0 讨论(0)
  • 2020-12-22 23:03

    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)

    0 讨论(0)
提交回复
热议问题