mirror of
https://github.com/metabolist/metatext.git
synced 2024-06-02 21:49:36 +00:00
30 lines
1,023 B
Swift
30 lines
1,023 B
Swift
//
|
|
// File.swift
|
|
//
|
|
//
|
|
// Created by Justin Mazzocchi on 9/2/20.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension FileManager {
|
|
func databaseDirectoryURL() throws -> URL {
|
|
let databaseDirectoryURL = try url(for: .applicationSupportDirectory,
|
|
in: .userDomainMask,
|
|
appropriateFor: nil,
|
|
create: true)
|
|
.appendingPathComponent("Database")
|
|
var isDirectory: ObjCBool = false
|
|
|
|
if !fileExists(atPath: databaseDirectoryURL.path, isDirectory: &isDirectory) {
|
|
try createDirectory(at: databaseDirectoryURL,
|
|
withIntermediateDirectories: false,
|
|
attributes: [.protectionKey: FileProtectionType.complete])
|
|
} else if !isDirectory.boolValue {
|
|
throw NSError(domain: NSCocoaErrorDomain, code: NSFileWriteFileExistsError, userInfo: nil)
|
|
}
|
|
|
|
return databaseDirectoryURL
|
|
}
|
|
}
|