How to set up Clang format for Allman style for iOS encoding?

I have a lot of confusion regarding the Clang Formats API.

  • I cannot open the .clangformat file so that I can examine it and configure it according to me.
  • I need to format my code in Allman style.
  • I saw a lot of google documentation and stack overflows, but I didn't get any help to achieve Allman style formatting.

I stumbled upon http://clangformat.com/ , but also did not get any help to achieve Allman style.

Here is the problem and the solution I want.

ISSUE No. 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 No. 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; } 
+6
source share
1 answer

You need to add the .clang file to the project root directory. As required, you can edit this file in TextEditor. The following is the Allman style format:

 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 that may help 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

Link to the Xcode project for creating and installing the clang format file: https://github.com/travisjeffery/ClangFormat-Xcode/blob/master/README.md

Bug fix .clang-format: https://github.com/travisjeffery/ClangFormat-Xcode/issues/68

Apple source code formatting options: https://developer.apple.com/legacy/library/documentation/DeveloperTools/Reference/XcodeUserDefaultRef/100-Xcode_User_Defaults/UserDefaultRef.html#//apple_ref/doc/uid/TP4000553557

Hope this helps!

+2
source

All Articles