2 // ApplicationDirecrories.swift
5 // Created by Hori,Masaki on 2017/02/08.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 private func supportDirName() -> String {
12 let main = Bundle.main
13 return main.bundleIdentifier
14 ?? main.infoDictionary?["CFBundleName"] as? String
15 ?? main.infoDictionary?["CFBundleExecutable"] as? String
16 ?? "UnknownAppliation"
19 struct ApplicationDirecrories {
21 static let support = searchedURL(for: .applicationSupportDirectory)
22 .appendingPathComponent(supportDirName())
24 static let documents = searchedURL(for: .documentDirectory)
26 static let pictures = searchedURL(for: .picturesDirectory)
28 private static func searchedURL(for directory: FileManager.SearchPathDirectory) -> URL {
30 return FileManager.default.urls(for: directory,
33 ?? URL(fileURLWithPath: NSHomeDirectory())
37 func checkDirectory(_ url: URL) -> Bool {
41 let p = try url.resourceValues(forKeys: [.isDirectoryKey])
43 print("Expected a folder to store application data, found a file \(url.path).")
47 let nserror = error as NSError
48 if nserror.code == NSFileReadNoSuchFileError {
52 .createDirectory(at: url,
53 withIntermediateDirectories: false,