I have a lot of confusion regarding Clang Format API.
I came across http://clangformat.com/ but there also I didn't get any help to achieve Allman style.
Here is the issue and the solution I want.
ISSUE #1:
[[NSNotificationCenter defaultCenter]
      addObserver:self
         selector:@selector(captureSearchFiltersNotificationWithSelection:)
             name:kSearchFiltersNotificationWithSelection
           object:nil];
NEED #1:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSearchFiltersNotificationWithSelection:)name:kSearchFiltersNotificationWithSelection object:nil];
ISSUE #2:
- (id)initWithNibName:(NSString *)nibNameOrNil
               bundle:(NSBundle *)nibBundleOrNil {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
                //        listings = [NSMutableArray new];
                self.navTitle = @"Buy";
                searchFilters = [SearchFilter new];
                if ([LocationManager locationManager].location == nil) {
                        selectedSortOption = kSortBuyRefineOptionUndefined;
                }
                else {
                        selectedSortOption = kSortBuyRefineOptionNearMeAsc;
                }
        }
        return self;
}
NEED #2:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil 
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        listings = [NSMutableArray new];
        self.navTitle = @"Buy";
        searchFilters = [SearchFilter new];
        if ([LocationManager locationManager].location == nil) 
        {
            selectedSortOption = kSortBuyRefineOptionUndefined;
        }
        else 
        {
            selectedSortOption = kSortBuyRefineOptionNearMeAsc;
        }
    }
    return self;
}
                You can install clang-format and git-clang-format via npm install -g clang-format . To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows.
If you have the llvm toolchain already installed, you can find the clang-format.py file in /usr/local/opt/llvm/share/clang/clang-format.py without having to install a separate clang-format binary through Homebrew.
clang-format is located in clang/tools/clang-format and can be used to format C/C++/Obj-C code.
You need to add a .clang-format file in your project root directory. As per the requirement you can edit this file in TextEditor. Below is the format for "Allman" style:
BasedOnStyle: None
AlignTrailingComments: true
BreakBeforeBraces: Allman
ColumnLimit: 0
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PointerBindsToType: false
SpacesBeforeTrailingComments: 1
TabWidth: 8
UseTab: Never
Below are some links which can be helpful to you:
http://staxmanade.com/2015/01/how-to-install-clang-format-and-formatting-objective-c-files/
http://tonyarnold.com/2014/05/31/autoformatting-your-code.html
http://clang.llvm.org/docs/ClangFormatStyleOptions.html
http://blog.manbolo.com/2015/05/14/code-beautifier-in-xcode
Xcode project link to generate and install clang-format file: https://github.com/travisjeffery/ClangFormat-Xcode/blob/master/README.md
Fixing .clang-format issue: https://github.com/travisjeffery/ClangFormat-Xcode/issues/68
Apple's source code formatting options: https://developer.apple.com/legacy/library/documentation/DeveloperTools/Reference/XcodeUserDefaultRef/100-Xcode_User_Defaults/UserDefaultRef.html#//apple_ref/doc/uid/TP40005535-CH3-SW57
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With