Skip to content

Commit

Permalink
Merge pull request #4 from fguchelaar/Swift4.1
Browse files Browse the repository at this point in the history
Fixes deprecations for Swift 4.1
  • Loading branch information
s4cha authored Apr 11, 2018
2 parents ade30d7 + e686500 commit 8e1a33f
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions Classes/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,26 @@ func localizedStrings(inStringFile: String) -> [String] {
func listUsedAssetLiterals() -> [String] {
let enumerator = FileManager.default.enumerator(atPath:sourcePath)
print(sourcePath)
return elementsInEnumerator(enumerator)
.filter { $0.hasSuffix(".m") || $0.hasSuffix(".swift") || $0.hasSuffix(".xib") || $0.hasSuffix(".storyboard") } // Only Swift and Obj-C files
.map { "\(sourcePath)/\($0)" } // Build file paths
.map { try? String(contentsOfFile: $0, encoding: .utf8)} // Get file contents
.flatMap{$0}
.flatMap{$0} // Remove nil entries
.map(localizedStrings) // Find localizedStrings ocurrences
.flatMap{$0} // Flatten

#if swift(>=4.1)
return elementsInEnumerator(enumerator)
.filter { $0.hasSuffix(".m") || $0.hasSuffix(".swift") || $0.hasSuffix(".xib") || $0.hasSuffix(".storyboard") } // Only Swift and Obj-C files
.map { "\(sourcePath)/\($0)" } // Build file paths
.map { try? String(contentsOfFile: $0, encoding: .utf8)} // Get file contents
.compactMap{$0}
.compactMap{$0} // Remove nil entries
.map(localizedStrings) // Find localizedStrings ocurrences
.flatMap{$0} // Flatten
#else
return elementsInEnumerator(enumerator)
.filter { $0.hasSuffix(".m") || $0.hasSuffix(".swift") || $0.hasSuffix(".xib") || $0.hasSuffix(".storyboard") } // Only Swift and Obj-C files
.map { "\(sourcePath)/\($0)" } // Build file paths
.map { try? String(contentsOfFile: $0, encoding: .utf8)} // Get file contents
.flatMap{$0}
.flatMap{$0} // Remove nil entries
.map(localizedStrings) // Find localizedStrings ocurrences
.flatMap{$0} // Flatten
#endif
}


Expand Down

0 comments on commit 8e1a33f

Please sign in to comment.