Search code examples
xcodeformattingindentationautoformatting

In XCode, is there a way to automatically indent lines when I complete a block


I thought I had this before, but I must've changed a setting or something...

But say I have some code,

number = 1
number2 = 2

but now I want an if statement to wrap it

if(flag)
{
number = 1
number2 = 2

After I place the "}", is there a setting that will automatically indent those 2 lines in the block?

if(flag)
{
  number = 1
  number2 = 2
}

Thanks in advance!


Solution

  • I normally add the if statement, type { at the end of the line, hit return. This produces the block with the closing }. Then I cut-paste the code into this block - it will be indented automatically.

    You can also select the code and hit cmd-] to shift it to the right.