2

When I write a method that is a bit complicated I prefer to add a little comment block above it as

/*--------------------------------------------------------------+
| When I wrote this, only God and I understood what I was doing
| Now, God only knows
+-------------------------------------------------------------*/
- (void) overlyDifficultMethodToGrasp { ... }

Is it really so that the only way to comment out this method from my code would be to hit cmd + /? Which would result in

///*--------------------------------------------------------------+
// | When I wrote this, only God and I understood what I was doing
// | Now, God only knows
// +-------------------------------------------------------------*/
//- (void) overlyDifficultMethodToGrasp { ... }
//    

What I would like to do is

/*
/*--------------------------------------------------------------+
 | When I wrote this, only God and I understood what I was doing
 | Now, God only knows
 +-------------------------------------------------------------*/
- (void) overlyDifficultMethodToGrasp { ... }
*/

Which, as you can see, doesn't work...

Why? Well I think large chunks of // are ugly!

1

3 Answers 3

4

This has not much to do with Xcode, but with the language (and compiler) you're using. You can't have nested comment blocks like that in C or Objective-C.

Sign up to request clarification or add additional context in comments.

Comments

3

As DrummerB pointed out, you can't nest comments.

Use // for the fancy comments instead of /*

here:

/*

//--------------------------------------------------------------+
// When I wrote this, only God and I understood what I was doing
// Now, God only knows
//+-------------------------------------------------------------+

- (void) overlyDifficultMethodToGrasp { ... }
*/

Comments

0

It's possible to use a workaround for the lack of an easy nested comment shortcut. The workaround involves snippets.

First create a code snippet with /* newline */ (see shift + command + l).

Then multi-select the cursor above and under the lines of the comments you want to comment out.

Press shift + command + l, and select the snippet for nested comments in the Xcode library.

Make sure to select two cursors that wrap around the comment lines. That way, the snippet will automatically place the two parts of the snippets (/* and */) exactly around your comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.