|
1 | 1 | import Foundation |
2 | 2 |
|
3 | 3 | public struct FileFinder { |
4 | | - |
| 4 | + |
5 | 5 | #if compiler(>=5.3) |
6 | 6 | /// Version that works if you're using the 5.3 compiler or above |
7 | 7 | /// - Parameter filePath: The full file path of the file to find. Defaults to the `#filePath` of the caller. |
8 | 8 | /// - Returns: The file URL for the parent folder. |
9 | | - public static func findParentFolder(from filePath: StaticString = #filePath) -> URL { |
10 | | - self.findParentFolder(from: filePath.apollo.toString) |
11 | | - } |
| 9 | + public static func findParentFolder(from filePath: StaticString = #filePath) -> URL { |
| 10 | + self.findParentFolder(from: filePath.apollo.toString) |
| 11 | + } |
| 12 | + |
| 13 | + /// The URL of a file at a given path |
| 14 | + /// - Parameter filePath: The full file path of the file to find |
| 15 | + /// - Returns: The file's URL |
| 16 | + public static func fileURL(from filePath: StaticString = #filePath) -> URL { |
| 17 | + URL(fileURLWithPath: filePath.apollo.toString) |
| 18 | + } |
12 | 19 | #else |
13 | | - /// Version that works if you're using the 5.2 compiler or below |
14 | | - /// - Parameter file: The full file path of the file to find. Defaults to the `#file` of the caller. |
15 | | - /// - Returns: The file URL for the parent folder. |
16 | | - public static func findParentFolder(from filePath: StaticString = #file) -> URL { |
17 | | - self.findParentFolder(from: filePath.apollo.toString) |
18 | | - } |
| 20 | + /// Version that works if you're using the 5.2 compiler or below |
| 21 | + /// - Parameter file: The full file path of the file to find. Defaults to the `#file` of the caller. |
| 22 | + /// - Returns: The file URL for the parent folder. |
| 23 | + public static func findParentFolder(from filePath: StaticString = #file) -> URL { |
| 24 | + self.findParentFolder(from: filePath.apollo.toString) |
| 25 | + } |
| 26 | + |
| 27 | + /// The URL of a file at a given path |
| 28 | + /// - Parameter filePath: The full file path of the file to find |
| 29 | + /// - Returns: The file's URL |
| 30 | + public static func fileURL(from filePath: StaticString = #file) -> URL { |
| 31 | + URL(fileURLWithPath: filePath.apollo.toString) |
| 32 | + } |
19 | 33 | #endif |
20 | | - |
| 34 | + |
21 | 35 | /// Finds the parent folder from a given file path. |
22 | 36 | /// - Parameter filePath: The full file path, as a string |
23 | 37 | /// - Returns: The file URL for the parent folder. |
24 | | - public static func findParentFolder(from filePath: String) -> URL { |
25 | | - let url = URL(fileURLWithPath: filePath) |
26 | | - return url.deletingLastPathComponent() |
27 | | - } |
| 38 | + public static func findParentFolder(from filePath: String) -> URL { |
| 39 | + let url = URL(fileURLWithPath: filePath) |
| 40 | + return url.deletingLastPathComponent() |
| 41 | + } |
28 | 42 | } |
0 commit comments