gitリポジトリのurlを貼り付けるだけでアプリケーションのビルドを実行するアプリ。 macOS用
Revision | 50e05b5cd9e2721684c97f658da433cf32e992c1 (tree) |
---|---|
Zeit | 2017-08-13 13:54:47 |
Autor | masakih <masakih@user...> |
Commiter | masakih |
処理を効率化
@@ -16,34 +16,31 @@ final class ProjectFinder { | ||
16 | 16 | guard depth != 0 else { return nil } |
17 | 17 | |
18 | 18 | guard let contents = try? FileManager.default.contentsOfDirectory(at: url, |
19 | - includingPropertiesForKeys: [.isDirectoryKey]) | |
19 | + includingPropertiesForKeys: [.isDirectoryKey]) | |
20 | 20 | else { |
21 | 21 | return nil |
22 | 22 | } |
23 | 23 | |
24 | - if let url = contents.filter({ $0.pathExtension == "xcworkspace" }).first { | |
24 | + if let url = contents.lazy.filter({ $0.pathExtension == "xcworkspace" }).first { | |
25 | 25 | |
26 | 26 | return url |
27 | 27 | } |
28 | 28 | |
29 | - if let url = contents.filter({ $0.pathExtension == "xcodeproj" }).first { | |
29 | + if let url = contents.lazy.filter({ $0.pathExtension == "xcodeproj" }).first { | |
30 | 30 | |
31 | 31 | return url |
32 | 32 | } |
33 | 33 | |
34 | 34 | |
35 | - let dirs = contents.filter { | |
36 | - let att = try? $0.resourceValues(forKeys: [.isDirectoryKey]) | |
37 | - return att?.isDirectory ?? false | |
38 | - } | |
39 | - for d in dirs { | |
35 | + func isDir(_ url: URL) -> Bool { | |
40 | 36 | |
41 | - if let u = find(in: d, depth: depth - 1) { | |
42 | - | |
43 | - return u | |
44 | - } | |
37 | + return (try? url.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false | |
45 | 38 | } |
46 | 39 | |
47 | - return nil | |
40 | + return contents.lazy | |
41 | + .filter(isDir) | |
42 | + .flatMap { find(in: $0, depth: depth - 1) } | |
43 | + .first | |
44 | + | |
48 | 45 | } |
49 | 46 | } |