SQLite.swift
A type-safe, Swift-language layer over SQLite3.
A type-safe Swift library for SQLite that lets you define tables and run queries using Swift objects instead of raw SQL strings, catching type errors and typos at compile time, for iOS and Mac apps needing local data storage.
SQLite.swift is a Swift library for working with SQLite, a file-based database that runs inside your app rather than on a separate server. SQLite is widely used in iOS and Mac apps to store structured data locally on the device, things like user settings, downloaded content, or anything that needs to persist between app launches.
What this library adds on top of raw SQLite is a Swift-friendly interface. Instead of writing database queries as plain text strings, which can contain typos or type mistakes that only show up at runtime, you define your tables and columns as Swift objects. The library then catches errors at compile time, before you even run the app. If you try to insert the wrong type of data into a column or misspell a column name, the code will not compile.
The API is designed to feel natural in Swift. You create a table definition once, then use it to insert rows, query records with filters, update values, and delete entries. Each operation produces the corresponding SQL behind the scenes, but you do not have to write or read raw SQL unless you want to. The library also supports full-text search, encrypted databases via a companion library called SQLCipher, and database migration tools for updating your schema as your app evolves.
Installation works through the standard Swift package tools and also through CocoaPods and Carthage, which are older dependency managers common in Apple platform development. The library works on iOS, macOS, and Linux. It is MIT licensed and well documented, with a playground included in the Xcode project for hands-on exploration. This is a tool for Swift developers building apps that need local data storage without setting up a full database server.
Where it fits
- Store structured data locally in an iOS or Mac app using a type-safe Swift interface without writing raw SQL strings.
- Define a database schema with Swift objects so column typos and type mismatches are caught by the compiler before the app runs.
- Add full-text search or encrypted storage to an iOS app using SQLite.swift alongside the SQLCipher companion library.