Installation Guide
SQLite.swift can be integrated into your project using Swift Package Manager, Carthage, or CocoaPods. Follow the instructions below for your preferred dependency manager.
Swift Package Manager
The Swift Package Manager is the standard tool for managing Swift code distribution, fully integrated with the Swift build system.
-
Add SQLite.swift as a dependency in your
Package.swiftfile:dependencies: [ .package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.15.4") ] -
Add
SQLiteas a dependency to your target:targets: [ .target( name: "YourApp", dependencies: ["SQLite"]) ] -
Build your project:
$ swift build
Carthage
Carthage is a simple, decentralized dependency manager for Cocoa applications.
-
Ensure Carthage is installed. If not, you can install it with Homebrew:
brew install carthage -
Add the following line to your
Cartfile:github "stephencelis/SQLite.swift" ~> 0.15.4 -
Run
carthage updateto build the framework. -
Drag the built
SQLite.frameworkfrom theCarthage/Buildfolder into your Xcode project's "Frameworks, Libraries, and Embedded Content" section.
CocoaPods
CocoaPods is a widely-used dependency manager for Cocoa projects.
-
Ensure you have CocoaPods installed. It can be installed via RubyGems:
[sudo] gem install cocoapods -
Add the following to your
Podfile:use_frameworks! target 'YourAppTargetName' do pod 'SQLite.swift', '~> 0.15.0' end -
Run the pod installation command:
pod install --repo-update
Using a Specific Version of SQLite
By default, SQLite.swift links against the version of SQLite provided by the operating system. If you need a more recent version, you can use the standalone subspec. This will bundle a specific version of SQLite with your application.
target 'YourAppTargetName' do
pod 'SQLite.swift/standalone', '~> 0.15.4'
end
You can further customize this to include specific features like FTS5 by depending on a specific sqlite3 pod subspec:
target 'YourAppTargetName' do
pod 'SQLite.swift/standalone', '~> 0.15.4'
# This example uses SQLite 3.15.0 with FTS5 enabled
pod 'sqlite3/fts5', '= 3.15.0'
end
Using SQLCipher for Encryption
To add database encryption using SQLCipher, use the SQLCipher subspec. This will automatically add the SQLCipher dependency and extend Connection with encryption-specific methods.
Important: Only require the SQLCipher subspec to avoid linking against the system's SQLite library, which would cause SQLCipher-specific methods to fail.
target 'YourAppTargetName' do
pod 'SQLite.swift/SQLCipher', '~> 0.15.4'
end
This makes new methods available on your Connection object:
import SQLite
let db = try Connection("path/to/encrypted.sqlite3")
try db.key("a-very-secret-password")
// You can also change the key on an already-encrypted database
try db.rekey("a-new-secret-password")
Manual Installation
While dependency managers are recommended, you can also install SQLite.swift manually as an Xcode sub-project.
- Clone or download the SQLite.swift repository.
- Drag the
SQLite.xcodeprojfile into your project's file navigator in Xcode. - In your application target’s settings, go to the General tab.
- Under Frameworks, Libraries, and Embedded Content, click the + button.
- Select
SQLite.frameworkfor your target platform. - Ensure that
SQLite.frameworkis also present under the Build Phases tab in the Embed Frameworks section.
After installation, you can import SQLite in your Swift files to start using the library.