Storage
public class Storage
Storage can be used to save or cache objects that conform to Codable protocl.
See also
Codable-
Storage errors
See moreDeclaration
Swift
public enum StorageError : Error
-
File type, currently supporting .json
See moreDeclaration
Swift
public enum FileType : String
-
Directory to save data
See moreDeclaration
Swift
public enum Directory
-
Store an encodable struct to the specified directory on disk
Declaration
Parameters
object
the encodable struct to store
directory
where to store the struct. It is recommended by Apple to use the Library directory, which will save the app data files into the Library/Application Support Directory. The contents of this directory are backed up by iTunes and iCloud.
fileName
what to name the file where the struct data will be stored
-
Retrieve and convert a struct from a file on disk
Example: A simple
Resort
objectlet resorts = retrieve("resorts", of: .json, from: .documents, as: [Resort].self)
Declaration
Parameters
fileName
name of the file where struct data is stored
directory
directory where struct data is stored
type
struct type (i.e. Message.self)
Return Value
decoded struct model(s) of data
-
Remove all files at specified directory
Declaration
Swift
public static func clear(_ directory: Directory) throws
Parameters
directory
The directory to clean
-
Returns BOOL indicating whether file exists at specified directory with specified file name
Declaration
Parameters
fileName
The file name
fileType
The file type
directory
The directory to check if the file exists