2015-09-25 15 views
6

Tôi có rất nhiều sự nhầm lẫn về API Định dạng Clang.Làm thế nào để cấu hình Clang Format cho Allman style for iOS coding?

  1. Tôi không thể mở tệp .clangformat để tôi có thể xem xét và định cấu hình theo tôi.
  2. Tôi cần phải định dạng mã của mình theo kiểu Allman.
  3. Tôi cũng đã thấy rất nhiều tài liệu về Google và Stack Overflow nhưng tôi không nhận được bất kỳ trợ giúp nào để đạt được định dạng kiểu Allman.

Tôi đã xem qua số http://clangformat.com/ nhưng tôi cũng không nhận được bất kỳ trợ giúp nào để đạt được phong cách Allman.

Đây là vấn đề và giải pháp tôi muốn.

Issue # 1:

[[NSNotificationCenter defaultCenter] 
     addObserver:self 
     selector:@selector(captureSearchFiltersNotificationWithSelection:) 
      name:kSearchFiltersNotificationWithSelection 
      object:nil]; 

CẦN # 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; 
} 

CẦN # 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 Bất kỳ ý tưởng nào về câu trả lời? – Developer

+0

Re: "Tôi không thể mở tập tin .clangformat để tôi có thể xem xét và cấu hình theo tôi.", Bạn có thể làm rõ ý bạn là gì, vì nó không rõ ràng? Tên tệp thường phải là '.clang-format' hoặc' _clang-format' và được đặt trong thư mục dự án. –

+0

@ l'L'l Trong trình chỉnh sửa nào, tôi có thể xem nội dung của tệp ".clang-format"? – Developer

Trả lời

2

Bạn cần phải thêm một file .clang định dạng trong thư mục gốc của dự án của bạn. Theo yêu cầu, bạn có thể chỉnh sửa tệp này trong TextEditor. Dưới đây là các định dạng cho phong cách "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 

Dưới đây là một số liên kết mà có thể hữu ích cho bạn:

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 liên kết dự án để tạo ra và cài đặt tập tin kêu vang định dạng: https://github.com/travisjeffery/ClangFormat-Xcode/blob/master/README.md

Sửa vấn đề .clang định dạng: https://github.com/travisjeffery/ClangFormat-Xcode/issues/68

mã nguồn của Apple tùy chọn định dạng: 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!

+0

Bạn nên đọc lại câu hỏi của tôi. Và cũng về Định dạng Clang. Tôi nghĩ bạn không phải là câu hỏi của tôi. – Developer

+0

Tôi có lớp định dạng .clang ở thư mục gốc nhưng tôi cần phải biết cách cấu hình cho Allman Style. Nếu bạn muốn tôi có thể gửi cho bạn tệp đó hoặc bạn gửi tệp được định dạng. – Developer

+0

Tôi đã đọc tất cả tài liệu và cũng đã định cấu hình tệp như bạn đã đề cập nhưng vẫn không hoạt động. Vui lòng tạo một mã mẫu với các sự cố của tôi và kiểm tra tệp của bạn. Và vui lòng cho tôi biết nếu điều đó làm việc cho bạn. Bạn cũng có thể chia sẻ màn hình ghi âm. – Developer

Các vấn đề liên quan