FileBackedDictionaryError
enum FileBackedDictionaryError : Error
Encapsulates a [String:T]
dictionary whose values are automatically persisted (each in its own file).
Exposes methods and properties similar to those of the Swift Dictionary.
Usage examples:
Create a FileBackedDictionary
instance, using Documents subdirectory named Resources
and struct Resource
as the value type.
let directoryName = "Resources"
var fbDict = FileBackedDictionary<Resource>(directoryName: directoryName)
Add resource instances
fbDict["apples"] = Resource(name: "apples", value: 1, quantity: 1)
fbDict["oranges"] = Resource(name: "oranges", value: 2, quantity: 2)
fbDict["mangos"] = Resource(name: "mangos", value: 3, quantity: 3)
Look up the resource info
let count = bDict.count // 3
let keys = fbDict.keys // ["apples", "oranges", "mangos"])
let values = fbDict.values // ...
let myOranges = fbDict["oranges"]
Remove resources
fbDict["oranges"] = nil
fbDict.removeAll()
At its initialization (typically at the application start), an instance of FileBackedDictionary
recovers the keys and values from the file storage.
-
Declaration
Swift
case encodingError
-
Declaration
Swift
case writingError(Error)
-
Declaration
Swift
case readingError