Just some tools to make handling Data storage easier.
This framework will be usable by iOS 13 and above or MacOS 10.15 and above.
LNFileUtils is available via SwiftPackage.
Add the following to you Package.swift file's dependencies:
.package(url: "https://github.com/sciasxp/LNSFileUtils.git", from: "0.2.0"),
Save/Retrieve/Remove Data to UserDefaults with Key identifier.
Save/Retrieve/Remove Data to FileSystem with Key identifier.
UIImage extension to easily cache your images in different formats and compression quality.
import LNFileUtils
let utils = FileUtils.shared
do {
try utils.store (
key: "defaultStorageTest",
data: <#Your Data Here#>,
on: .userDefaults
)
} catch {}
let utils = FileUtils.shared
do {
let data: Data? = try utils.retrieve (
key: "defaultStorageTest",
on: .userDefaults
)
} catch {}
let utils = FileUtils.shared
do {
try utils.remove (
key: "defaultStorageTest",
on: .userDefaults
)
} catch {}
let utils = FileUtils.shared
do {
let url = try utils.store (
key: "fileSystemCacheStorageTest",
data: <#Your Data Here#>,
on: .fileSystem(place: .cache)
)
} catch {}
let utils = FileUtils.shared
do {
let data: Data? = try utils.retrieve (
key: "fileSystemCacheStorageTest",
on: .fileSystem(place: .cache)
)
} catch {}
let utils = FileUtils.shared
do {
try utils.remove (
key: "fileSystemCacheStorageTest",
on: .fileSystem(place: .cache)
)
} catch {}
place can be one of three values:
cache
document
library
let image = UIImage(systemName: "clock")!
do {
try referenceImage.storeCache (
with: "fileSystemCacheUIImageExtension",
on: .fileSystem(place: .cache),
as: .png
)
} catch {}
Where on is same as place on FileUtils and as can be any of these formats:
.jpg(quality: 1.0)
.png
.heic
.qoi (more about QOI format here: https://github.com/sciasxp/SwiftQOI)
do {
let image = try UIImage.image (
with: "fileSystemCacheUIImageExtension",
on: .fileSystem(place: .cache),
as: .png
)
} catch {}
## Future Work
Improve unit tests.
Improve documentation.
Support for cocoapods
You are most welcome in contributing to this project with either new features (maybe one mentioned from the future work or anything else), refactoring and improving the code. Also, feel free to give suggestions and feedbacks.
Created with ❤️ by Luciano Nunes.
Get in touch on [Email](https://raw.github.com/sciasxp/LNFileUtils/main/mailto: [email protected])
Visit: LinkdIn
link |
Stars: 0 |
Last commit: 1 year ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics