If you are using the Codable protocol and need an easy way to store and retrieve your objects, you are in the right place. Swift Storage is a simple extension to store/retrieve your Codable objects.
- Store Codable objects
- Retrieve stored Codable objects
- Store Locations
- Cache
- Documents
- User Default
- NSUbiquitousKeyValueStore
- Linux compatibility
- Name Spaced Stores
- Comprehensive Unit and Integration Test Coverage
- Complete Documentation
Considering you have a Codable Job struct like below
struct Job: Codable {
let company: String
let position: String
let description: String
let url: String
}To save or retrieve array of Job
import SwiftStorage
// Create a instance of `Storage` with a type and file name
let storage: Storage<[Job]> = Storage(storageType: .document, filename: "remote-jobs.json")
// To Save array of `Job`
storage.save([job1, job2])
// To retrieve stored values of jobs
let jobs = storage.storedValue
// To remove the stored values
storage.clear()The available storage types are .cache, .document, .userDefaults and .ubiquitousKeyValueStore.
To run the example project, clone the repo, open Example/Storage.xcodeproj in Xcode and run the Storage-Example scheme. The project references the package locally, so there is no install step.
Run the test suite from the repository root:
swift test- Xcode 27+ / Swift 6.2+
- iOS 26+
Swift Storage is distributed through the Swift Package Manager only. CocoaPods is not supported.
In Xcode, choose File > Add Package Dependencies..., enter the repository URL below, and add the SwiftStorage library to your target:
https://github.com/rizwankce/Storage.git
Add the package as a dependency:
dependencies: [
.package(url: "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/rizwankce/Storage.git", from: "1.0.0")
]Then, add SwiftStorage as a dependency of your target:
.target(
name: "YourTargetName",
dependencies: [
.product(name: "SwiftStorage", package: "Storage")
]),If you like to contribute to this project, feel free to send PR or raise issues.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
The idea of Swift Storage is originally came from Ben Scheirman from NSScreenCast and most of the code is inspired from one of his series and extended a little with more options.
Storage is available under the MIT license. See the LICENSE file for more info.