How can I configure Xcode to put '{' where I want it in generated files

前端 未结 4 1688
一整个雨季
一整个雨季 2021-02-14 10:10

I know this is a fairly contentious issue amongst programmers, but when developing I like my IDE to position the opening curly bracket underneath the method/interface/control de

相关标签:
4条回答
  • 2021-02-14 10:52

    After digesting the helpful information from WhirlWind above (thanks), the resulting snippet (just cut and paste into terminal) is:

    defaults write com.apple.Xcode XCCodeSenseFormattingOptions -dict BlockSeparator "\\n" PreMethodDeclSpacing ""

    Stupid backslash quoting. When typed at the terminal, there should be TWO exactly TWO backslashes in the block separator.

    0 讨论(0)
  • 2021-02-14 11:00

    I believe that "defaults write com.apple.Xcode" doesn't work on the latest versions of Xcode (7.x)

    Here are the solutions I know:

    1. Snippet Edit -- this little program will allow to edit default Xcode's code snippets. So, you will be able to open braces from new line in your if, for, while, etc. However, this doesn't allow to change the block indentation.

    2. Uncrustify -- this might solve your problem too, but it doesn't look like being easy to set up. And it only formats the code after it is already written, instead of formatting 'on the go'.

    0 讨论(0)
  • 2021-02-14 11:03

    Take a look at:

    Xcode: Adjusting indentation of auto-generated braces?

    Apple Xcode User Defaults

    XCCodeSenseFormattingOptions = {
      BlockSeparator = "\\n";
      PreMethodDeclSpacing = "";
    };
    

    This should at least solve your problem after if, for, or while statements.

    0 讨论(0)
  • 2021-02-14 11:08

    Even with those settings, it does not appear to work with the templates. If you set this and then type "init" in a .m file you get:

    - (id)init
    {
      self = [super init];
      if (self) {
        <#initializations#>
      }
      return self;
    }
    

    Note the "if (self) {" line.

    0 讨论(0)
提交回复
热议问题