Skip to content
Husnain Ali edited this page Sep 27, 2026 · 5 revisions

SwiftLocalStorage saves the Codable structs your app already has, using SwiftData under the hood. You don't write @Model classes or mapping code, and SwiftData never leaks into your domain layer. The structs your API returns are the same ones you store.

It has no dependencies, is built for Swift 6 strict concurrency, and runs on iOS 17, macOS 14, tvOS 17, watchOS 10 and visionOS 1 or later.

Install

dependencies: [
    .package(url: "https://github.com/ihusnainalii/SwiftLocalStorage.git", from: "1.1.1"),
]

In Xcode: File ▸ Add Package Dependencies…, paste the repository URL and choose Up to Next Major Version.

A quick look

import SwiftLocalStorage

struct User: Codable, Identifiable, Sendable {
    let id: Int
    var name: String
    var role: String
}

let storage = try LocalStorage()

try await storage.save(User(id: 1, name: "Ada", role: "admin"), expiration: .hours(1))
let ada   = try await storage.fetch(User.self, id: 1)
let users = try await storage.fetch(User.self, options: FetchOptions(sort: .newestFirst, limit: 20))

for try await users in storage.updates(of: User.self) {     // live query for SwiftUI
    print(users.count)
}

Where to go next

Feature Page
What happens when you save, read, or watch data How It Works
Entity CRUD, key-value entries, cache expiration, metadata, repositories Getting Started
Sorting, paging, closure filters, batched iteration Querying
Up to three indexed fields per type, in-store filters (equals, ranges, hasPrefix, oneOf), ordering, counts, pages, live indexed queries Indexed Fields
Typed change feeds and coalescing live queries Observing Changes
Versioned DTOs with typed or raw-JSON migration steps Migrating Stored DTOs
In-memory stores and clock injection for tests and previews Testing
What 1.x promises API Stability
Timings on real hardware Benchmarks
Moving between versions Upgrading
Questions and known limitations FAQ

More

Clone this wiki locally