Skip to content

🗂️ Your easy-to-use solution for persisting data in files when building CLI tools with Swift.

License

Notifications You must be signed in to change notification settings

GabrielaBezerra/FileKeeper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FileKeeper

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.

Installation

Swift Package Manager

dependencies: [
    //...
    .package(url: "https://github.com/GabrielaBezerra/FileKeeper.git", branch: "main")
],
targets: [
    .executableTarget(
        name: "yourprojectname",
        dependencies: [
            //...
            .product(name: "FileKeeper", package: "FileKeeper")
        ]
    )
]

Usage

Initial setup

FileKeeper.projectName = "YourProjectName"

Save a JSON file

let encodableModel = Model()
try FileKeeper.saveJson(encodableModel, at: "yourfolder/yourfilename.json")
// saved in `~/.yourprojectname/yourfolder/yourfilename.json`

Read a JSON file

let encodableModel = try FileKeeper.readJson(at: "yourfolder/yourfilename.json")
// read from `~/.yourprojectname/yourfolder/yourfilename.json`

Save a Plain Text file

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`

Read a Plain Text file

try FileKeeper.readPlainText(at: "yourfolder/yourfilename.txt")
// read from `~/.yourprojectname/yourfolder/yourfilename.txt`

About

🗂️ Your easy-to-use solution for persisting data in files when building CLI tools with Swift.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages