static let shared = ApplicationDirecrories()
- static let support = searchedURL(for: .applicationSupportDirectory)
+ let support = searchedURL(for: .applicationSupportDirectory)
.appendingPathComponent(supportDirName())
- static let documents = searchedURL(for: .documentDirectory)
+ let documents = searchedURL(for: .documentDirectory)
- static let pictures = searchedURL(for: .picturesDirectory)
+ let pictures = searchedURL(for: .picturesDirectory)
- private static func searchedURL(for directory: FileManager.SearchPathDirectory) -> URL {
+ static func searchedURL(for directory: FileManager.SearchPathDirectory) -> URL {
return FileManager.default.urls(for: directory, in: .userDomainMask)
.last
}
}
-
-func createDirectory(_ url: URL) -> Bool {
+extension ApplicationDirecrories {
- do {
-
- try FileManager.default.createDirectory(at: url,
- withIntermediateDirectories: false,
- attributes: nil)
-
- return true
+ func createDirectory(_ url: URL) -> Bool {
- } catch {
-
- return false
- }
-}
-
-func checkDirectory(_ url: URL, create: Bool) -> Bool {
-
- do {
-
- let resourceValue = try url.resourceValues(forKeys: [.isDirectoryKey])
- if !resourceValue.isDirectory! {
+ do {
+
+ try FileManager.default.createDirectory(at: url,
+ withIntermediateDirectories: false,
+ attributes: nil)
+
+ return true
- print("Expected a folder to store application data, found a file \(url.path).")
+ } catch {
return false
}
+ }
+
+ func checkDirectory(_ url: URL, create: Bool) -> Bool {
- return true
-
- } catch let error as NSError {
-
- if create, error.code == NSFileReadNoSuchFileError {
+ do {
+
+ let resourceValue = try url.resourceValues(forKeys: [.isDirectoryKey])
+ if !resourceValue.isDirectory! {
+
+ print("Expected a folder to store application data, found a file \(url.path).")
+
+ return false
+ }
- return createDirectory(url)
+ return true
+
+ } catch let error as NSError {
+
+ if create, error.code == NSFileReadNoSuchFileError {
+
+ return createDirectory(url)
+ }
+
+ return false
}
-
- return false
}
}
static let kcd = URLCache(memoryCapacity: 32 * 1024 * 1024,
diskCapacity: 1024 * 1024 * 1024,
- diskPath: ApplicationDirecrories.support.appendingPathComponent("Caches").path)
+ diskPath: ApplicationDirecrories.shared.support.appendingPathComponent("Caches").path)
static let cachedExtensions = ["swf", "flv", "png", "jpg", "jpeg", "mp3"]
func storeIfNeeded(for task: URLSessionTask, data: Data) {