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: 24 days 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 (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-16T14:45:17.000Z (2 months ago)
- Last Synced: 2024-10-07T01:41:48.257Z (about 1 month 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
![XCtests](https://github.com/rudifa/RudifaUtilPkg/workflows/build_and_test/badge.svg)
![XCtests](https://github.com/rudifa/RudifaUtilPkg/workflows/build_jazzy_docs/badge.svg)[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()
```