2015-09-25 31 views
6

我对Clang Format API有很多疑惑。如何为iOS编码配置Allman风格的Clang格式?

  1. 我无法打开.clangformat文件,以便我可以查看该文件并根据我进行配置。
  2. 我需要以Allman风格格式化我的代码。
  3. 我已经看过很多关于Google和Stack Overflow的文档,但是我没有得到任何帮助来实现Allman样式格式。

我碰到了http://clangformat.com/但我也没有得到任何帮助实现Allman风格。

这是问题和我想要的解决方案。

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; 
} 
+0

@halfer有关答案的任何想法? – Developer

+0

回复:“我无法打开.clangformat文件,以便我可以查看并根据我进行配置。”,您能否澄清您的意思,因为它尚不清楚?文件名通常应该是'.clang-format'或'_clang-format'并放置在项目目录中。 –

+0

@ l'l l在哪个编辑器中,我可以看到“.clang-format”文件的内容? – Developer

回答

2

您需要添加.clang格式文件在你的项目的根目录。根据要求,您可以在TextEditor中编辑此文件。下面是 “奥尔曼” 样式的格式:

BasedOnStyle: None 
AlignTrailingComments: true 
BreakBeforeBraces: Allman 
ColumnLimit: 0 
IndentWidth: 4 
KeepEmptyLinesAtTheStartOfBlocks: false 
ObjCSpaceAfterProperty: true 
ObjCSpaceBeforeProtocolList: true 
PointerBindsToType: false 
SpacesBeforeTrailingComments: 1 
TabWidth: 8 
UseTab: Never 

下面是一些链接,可以对您有所帮助:

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项目链接,生成和安装铛格式文件: https://github.com/travisjeffery/ClangFormat-Xcode/blob/master/README.md

固定.clang格式问题: https://github.com/travisjeffery/ClangFormat-Xcode/issues/68

苹果的源代码格式选项: https://developer.apple.com/legacy/library/documentation/DeveloperTools/Reference/XcodeUserDefaultRef/100-Xcode_User_Defaults/UserDefaultRef.html#//apple_ref/doc/uid/TP40005535-CH3-SW57

希望这有助于!

+0

您应该再次阅读我的问题。还有关于Clang格式。我想你不是我的问题。 – Developer

+0

我在根目录下有.clang格式的类,但我需要知道如何配置Allman Style。如果你想我可以给你发送该文件或发送格式化文件。 – Developer

+0

我已经阅读了所有的文档,并且还配置了文件,就像您提到的那样,但它仍然无法正常工作。请用我的问题创建一个示例代码并测试您的文件。请让我知道,如果这对你有用。您也可以共享屏幕录制。 – Developer