Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rudifa/rudifautilpkg
Small Swift extensions that make my life easier, see the docs.
https://github.com/rudifa/rudifautilpkg
Last synced: 4 months ago
JSON representation
Small Swift extensions that make my life easier, see the docs.
- Host: GitHub
- URL: https://github.com/rudifa/rudifautilpkg
- Owner: rudifa
- Created: 2020-08-25T16:28:02.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-16T14:45:17.000Z (5 months ago)
- Last Synced: 2024-10-07T01:41:48.257Z (5 months ago)
- Language: Swift
- Homepage:
- Size: 381 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RudifaUtilPkg

[RudifaUtilPkg](https://rudifa.github.io/RudifaUtilPkg/) contains swift extensions and utility methods.
## Highlights
### FileBackedDictionary
`struct FileBackedDictionary` encapsulates a `[String:T]` dictionary whose values are automatically persisted, each in its own file.
`FileBackedDictionary` exposes methods and properties similar to those of the Swift Dictionary.
At its initialization (typically at the application start), an instance of `FileBackedDictionary` recovers the keys and values from the file storage (if any have been stored in previous application runs).
### Usage examples ###
Create a `FileBackedDictionary` instance, with a directory named `MyResources` and `struct Resource` as type of the values to store.
```
let directoryName = "MyResources"
var fbDict = FileBackedDictionary(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 = fbDict.count // 3
let keys = fbDict.keys // ["apples", "oranges", "mangos"])
let values = fbDict.values // [...]
let myOranges = fbDict["oranges"]
```Remove resources
```
fbDict["oranges"] = nil
fbDict.removeAll()
```