Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode Command-Slash Shortcut to Comment Only Works Sometimes

I'm having issues with Xcode being quite unreliable when using the keyboard shortcut to comment or uncomment code +/. I can't seem to find a real pattern as to when it breaks, but it usually happens after building and running my code on the simulator. It will not work again until I edit something in any one of my code files. Even if I switch to another file in the main view, commenting via shortcut does not work. Other keyboard shortcuts, such as indenting +[ continue to work just fine.

Do other people have this issue, and if so, have you found a solution? I know it seems like a small complaint, but when running and then quickly trying to comment out a block of code to check the effect, it's a bit of an inconvenience.

I am using Xcode 6.1 (6A1052d) on OXS Yosemite 10.10 (14A389) and developing in Objective-C for iOS if that matters.

like image 535
Stonz2 Avatar asked Oct 29 '14 13:10

Stonz2


People also ask

How do I comment out a block of code in Xcode?

6. Comments By selecting a few lines of code (pressing ⇧+↑ or ⇧+↓), you can comment a bunch of lines in a single shot with the ⌘ + / shortcut. If the lines are already comments, the same shortcut will uncomment them.

How do I comment out multiple lines in Xcode C++?

Is there a way to comment various lines at the same time in Xcode IDE? Selecting which lines to comment, then clicking somewhere et voilá.. the /* ... */ characters wrapping the code. Thank you.

How do I block comments in Swift?

Use a forward slash ( / ) followed by an asterisk ( * ) and then a colon ( : ) for the opening comment.


2 Answers

For an Xcode 8, solution is

sudo /usr/libexec/xpccachectl 

and restart your computer.

like image 200
CryingHippo Avatar answered Oct 06 '22 15:10

CryingHippo


Hit +] once and then +/ will start working again.

You can hit +[ to undo the indentation effect.

Update:

Please note- This solution was provided prior to Xcode 8 launch so it may not work for everyone. If you are still facing problem, kindly refer to @CryingHippo's answer instead of downvoting.

like image 45
atulkhatri Avatar answered Oct 06 '22 15:10

atulkhatri