我对Clang Format API感到很困惑。
我偶然遇到http://clangformat.com/,但我也没有得到任何帮助来实现奥尔曼的风格。
这是我想要的问题和解决方案。
问题#1:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(captureSearchFiltersNotificationWithSelection:)
name:kSearchFiltersNotificationWithSelection
object:nil];
需要#1:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSearchFiltersNotificationWithSelection:)name:kSearchFiltersNotificationWithSelection object:nil];
问题#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;
}
需要#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 :(得分:3)
您需要在项目根目录中添加.clang格式的文件。根据要求,您可以在TextEditor中编辑此文件。以下是" Allman"的格式。式:
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
生成并安装clang格式文件的Xcode项目链接: https://github.com/travisjeffery/ClangFormat-Xcode/blob/master/README.md
修复.clang格式问题: https://github.com/travisjeffery/ClangFormat-Xcode/issues/68
希望这有帮助!