FileKeeper is your easy-to-use solution for persisting data in files when building CLI tools with Swift. With FileKeeper, you can store and access data as needed in both JSON format or Plain Text. FileKeeper is built on top of the FileManager API, making it easy to use and understand.
dependencies: [
//...
.package(url: "https://github.com/GabrielaBezerra/FileKeeper.git", branch: "main")
],
targets: [
.executableTarget(
name: "yourprojectname",
dependencies: [
//...
.product(name: "FileKeeper", package: "FileKeeper")
]
)
]
FileKeeper.projectName = "YourProjectName"
let encodableModel = Model()
try FileKeeper.saveJson(encodableModel, at: "yourfolder/yourfilename.json")
// saved in `~/.yourprojectname/yourfolder/yourfilename.json`
let encodableModel = try FileKeeper.readJson(at: "yourfolder/yourfilename.json")
// read from `~/.yourprojectname/yourfolder/yourfilename.json`
let array = ["Adventures of Huckleberry Finn", "Alice's Adventures in Wonderland", "Moby-Dick"]
try FileKeeper.savePlainText(content: array, at: "yourfolder/yourfilename.txt")
// saved in `~/.yourprojectname/yourfolder/yourfilename.txt`
try FileKeeper.readPlainText(at: "yourfolder/yourfilename.txt")
// read from `~/.yourprojectname/yourfolder/yourfilename.txt`