Skip to content

Commit

Permalink
Merge pull request #1 from insanoid/swift-support
Browse files Browse the repository at this point in the history
Swift support added.
  • Loading branch information
Karthikeya Udupa KM committed Oct 15, 2015
2 parents e093a9f + 70c9b5b commit 1948c2f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions CleanHeaders/CleanHeaders.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ - (void)cleanHeaderAction {
}

- (NSString *)formatSelection:(NSString *)content {
// Let's assume all header files start with an #import, #include, or @import.
// Let's assume all header files start with an #import, #include, @import,
// import.
NSString *traditionalImportPrefix = @"#import";
NSString *frameworkImportPrefix = @"@import";
NSString *traditionalIncludePrefix = @"#include";
NSString *swiftPrefix = @"import";

// Convert the entire source into an array based on new lines.
// Hence the imports have to be alteast in new line to work.
Expand All @@ -95,7 +97,8 @@ - (NSString *)formatSelection:(NSString *)content {

BOOL isLineHeader = [cleansedLine hasPrefix:traditionalImportPrefix] ||
[cleansedLine hasPrefix:traditionalIncludePrefix] ||
[cleansedLine hasPrefix:frameworkImportPrefix];
[cleansedLine hasPrefix:frameworkImportPrefix] ||
[cleansedLine hasPrefix:swiftPrefix];

// If the line is a header and no header element has been detected so far,
// mark this as the start of the header segment.
Expand Down Expand Up @@ -169,7 +172,7 @@ - (void)formatRanges:(NSArray *)ranges

- (BOOL)shouldFormat:(IDESourceCodeDocument *)document {
return [[NSSet setWithObjects:@"c", @"h", @"cpp", @"cc", @"cxx", @"hh",
@"hpp", @"ipp", @"m", @"mm", nil]
@"hpp", @"ipp", @"m", @"mm", @"swift", nil]
containsObject:[[[document fileURL] pathExtension] lowercaseString]];
}

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

An Xcode plug-in to format your import headers in a systematic manner. It simply removes duplicates, spaces and sorts them alphabetically making it much more easier to read and avoid duplicate imports. Works with `@imports` and `#include` along with `#import`.


![Preview](https://raw.githubusercontent.com/insanoid/CleanHeaders-Xcode/master/diff_image.png)

## Installation
Expand Down

0 comments on commit 1948c2f

Please sign in to comment.