Implemented the "init(at: )" initialiser, the "pathString" computed property, and the "appendingPath(_: )" function for the URL+Extensions extension in the library target.

This commit is contained in:
2025-01-12 21:25:51 +01:00
parent 3a447b4f71
commit a1ad391baa
5 changed files with 114 additions and 38 deletions
@@ -0,0 +1,35 @@
import Foundation
extension URL {
// MARK: Initialisers
init(at filePath: String) {
if #available(macOS 13.0, *) {
self = URL(filePath: filePath)
} else {
self = URL(fileURLWithPath: filePath)
}
}
// MARK: Computed
var pathString: String {
if #available(macOS 13.0, *) {
path()
} else {
path
}
}
// MARK: Functions
func appendingPath(_ path: String) -> URL {
if #available(macOS 13.0, *) {
appending(path: path)
} else {
appendingPathComponent(path)
}
}
}
@@ -1,15 +0,0 @@
import Foundation
extension URL {
// MARK: Initialisers
init(at filePath: String) {
if #available(macOS 13.0, *) {
self = URL(filePath: filePath)
} else {
self = URL(fileURLWithPath: filePath)
}
}
}
+1 -17
View File
@@ -54,25 +54,9 @@ public struct FileService: FileServicing {
throw FileServiceError.urlNotFileURL
}
let filePath = getPath(for: url)
let filePath = url.pathString
return fileManager.fileExists(atPath: filePath)
}
}
// MARK: - Helpers
private extension FileService {
// MARK: Functions
func getPath(for url: URL) -> String {
if #available(macOS 13.0, *) {
return url.path()
} else {
return url.path
}
}
}
@@ -27,12 +27,8 @@ public struct CreateRootFolderTask {
} else {
await fileService.currentFolder
}
let newFolder = if #available(macOS 13.0, *) {
rootFolder.appending(path: name)
} else {
rootFolder.appendingPathComponent(name)
}
let newFolder = rootFolder.appendingPath(name)
try await fileService.createFolder(at: newFolder)