Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code-formatter for Objective-C

Similar questions have been asked before, but they didn't help me with what I'd like to do:

I want to re-format existing Objective-C code (several hundred files). For pure Apple-style formatting, uncrustify seems to do what I want. But for a few projects, I need a different style that I haven't found out how to configure uncrustify for. In this style, long method calls look like this (please refrain from discussing whether you like that style or not; do not suggest to use a different style):

[self
    longMethod:arg1
    withLots:arg2
    ofArguments:arg3
    aBlock:^{
       [self doSomething];
    }
    andAnotherBlock:^{
       [self doSomethingElse];
    }
];

This wrapping is done when the method call would exceed a line length of 80 or 100 characters. Each line is indented by one level and contains exactly one argument and the selector part up to the corresponding :. The lines thus are not colon-aligned.

No wrapping is done if the line length is below 80 or 100 characters:

[self shortMethod:withAnArgument];

Is there a code formatter that can be tweaked to support this style? If so, which and more importantly, how?

like image 761
DarkDust Avatar asked May 14 '14 12:05

DarkDust


2 Answers

Clang format can be used to format code in any number of styles. You can even specify the exact options you desire, or use one of several "standard" styles.

There is an XCode plugin as well.

like image 112
Jody Hagins Avatar answered Sep 23 '22 06:09

Jody Hagins


No, I do not think that there is code formatter for this style. You can use clang's Lib Tooling to do the job. Yes, you have to build you own tool using it. But developing your own tool is the usual way, if you want to do something very unusual.

like image 41
Amin Negm-Awad Avatar answered Sep 23 '22 06:09

Amin Negm-Awad