Question

I'm expecting Xcode to auto-indent my method when I type a colon, but it does not. I have Automatic indent for: ":" turned on. How can I get this to work?

Example:

  • type - (id)initWithName:(NSString *)name
  • press return
  • type value:(int)aValue
  • press return
  • type number:(int)aNumber;
  • press return

This is what I get

- (id)initWithName:(NSString *)name
value:(int)aValue
            number:(int)aNumber;

Why didn't it indent the second line??

Was it helpful?

Solution

I'm not sure the "why" is really answerable; it's annoying to be sure that Return doesn't seem to trigger auto-indent sometimes.

There's a workaround, though: before moving to the next line, you can type a semicolon. That triggers the indentation, and you can then delete it and hit Return.

It'll also indent properly if you type the method name out on one line first and then go back and insert the line breaks.

Neither of these are particularly wonderful options, of course.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top