Is there a shortcut to make a block comment in Xcode? Is there a shortcut to make a block comment in Xcode? xcode xcode

Is there a shortcut to make a block comment in Xcode?


Try command + /.

So, you just highlight the block of code you want to comment out and press those two keys.


UPDATE Xcode 12 / macOS Big Sur:

Currently the Mac App Store version of the BlockComment for Xcode doesn't show up under Xcode > Preferences > Key Bindings. This issue has been resolved and GitHub version can be used instead.

UPDATE June 2017:

Since I was lazy, and didn't fully implement my solution, I searched around and found BlockComment for Xcode, a recently released plugin (June 2017). Don't bother with my solution, this plugin works beautifully, and I highly recommend it.

ORIGINAL ANSWER:

None of the above worked for me on Xcode 7 and 8, so I:

  1. Created Automator service using AppleScript

  2. Make sure "Output replaces selected text" is checked

  3. Enter the following code:

    on run {input, parameters}return "/*\n" & (input as string) & "*/"end run

enter image description here

Now you can access that service through Xcode - Services menu, or by right clicking on the selected block of code you wish to comment, or giving it a shortcut under System Preferences.


Now with xCode 8 you can do:

+ + /

to auto-generate a doc comment.

Source: https://twitter.com/felix_schwarz/status/774166330161233920