DiskService
public class DiskService
A service class to write and read data from the devices documents directory
-
Write an instance of
Datato a given fileNameDeclaration
Swift
public static func write(data: Data, toFileName: String, isExcludedFromBackup: Bool = true) -> BoolReturn Value
Bool, indicating if the operation was successful
-
Write an instance of an object conforming to
Encodableto a fileNameDeclaration
Swift
public static func write<T>(encodable: T, toFileName: String, isExcludedFromBackup: Bool = true) -> Bool where T : EncodableReturn Value
Bool, indicating if the operation was successful
-
Read a fileName and return the contents as
DataDeclaration
Swift
public static func readData(fromFileName: String) -> Data?Return Value
Data, if able to read file -
Read a fileName, and parse the contents as an instance of a
DecodableobjectDeclaration
Swift
public static func read<T>(type: T.Type, fromFileName: String) -> T? where T : DecodableReturn Value
An instance of the
Decodabletype, if able to read file and parse it
-
Fetch a remote file and optionally store it in a supplied folder in the documents directory
Declaration
Swift
public static func fetchRemoteFile(url: URL, storeInFolder: String?, completion: @escaping ((Result<URL, Error>) -> Void)) -
Check the contents of a folder and delete the files if older than a given date
Declaration
Swift
public static func clearFiles(inFolder: String, olderThanDays: Int, completion: @escaping ((Error?) -> Void)) -
Return the size, in bytes, of a given folder in the documents directory
Declaration
Swift
public static func sizeOfFolder(_ folder: String) -> Int?
-
Delete a fileName
Declaration
Swift
public static func delete(fileName: String) -> BoolReturn Value
Bool, indicating if the operation was successful
-
Declaration
Swift
public static func delete(fileNames: [String]) -> Bool
-
Get the URL to the devices documents directory, if possible
Declaration
Swift
public static func documentsDirectory(isExcludedFromBackup: Bool = true) -> URL? -
Check if a fileName exists in the documents directory or not
Declaration
Swift
public static func exists(fileName: String) -> URL? -
Find all files in documents directory begining with prefix
Declaration
Swift
public static func allFileNamesWith(prefix: String) -> [String]
Install in Dash