DiskService
public class DiskService
A service class to write and read data from the devices documents directory
-
Write an instance of
Data
to a given fileNameDeclaration
Swift
public static func write(data: Data, toFileName: String, isExcludedFromBackup: Bool = true) -> Bool
Return Value
Bool, indicating if the operation was successful
-
Write an instance of an object conforming to
Encodable
to a fileNameDeclaration
Swift
public static func write<T>(encodable: T, toFileName: String, isExcludedFromBackup: Bool = true) -> Bool where T : Encodable
Return Value
Bool, indicating if the operation was successful
-
Read a fileName and return the contents as
Data
Declaration
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
Decodable
objectDeclaration
Swift
public static func read<T>(type: T.Type, fromFileName: String) -> T? where T : Decodable
Return Value
An instance of the
Decodable
type, if able to read file and parse it
-
Delete a fileName
Declaration
Swift
public static func delete(fileName: String) -> Bool
Return 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]