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.

  1. Add SQLite.swift as a dependency in your Package.swift file:

    dependencies: [
        .package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.15.4")
    ]
  2. Add SQLite as a dependency to your target:

    targets: [
        .target(
            name: "YourApp",
            dependencies: ["SQLite"])
    ]
  3. Build your project:

    $ swift build

Carthage

Carthage is a simple, decentralized dependency manager for Cocoa applications.

  1. Ensure Carthage is installed. If not, you can install it with Homebrew: brew install carthage

  2. Add the following line to your Cartfile:

    github "stephencelis/SQLite.swift" ~> 0.15.4
  3. Run carthage update to build the framework.

  4. Drag the built SQLite.framework from the Carthage/Build folder into your Xcode project's "Frameworks, Libraries, and Embedded Content" section.

CocoaPods

CocoaPods is a widely-used dependency manager for Cocoa projects.

  1. Ensure you have CocoaPods installed. It can be installed via RubyGems:

    [sudo] gem install cocoapods
  2. Add the following to your Podfile:

    use_frameworks!
    
    target 'YourAppTargetName' do
        pod 'SQLite.swift', '~> 0.15.0'
    end
    
  3. 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.

  1. Clone or download the SQLite.swift repository.
  2. Drag the SQLite.xcodeproj file into your project's file navigator in Xcode.
  3. In your application target’s settings, go to the General tab.
  4. Under Frameworks, Libraries, and Embedded Content, click the + button.
  5. Select SQLite.framework for your target platform.
  6. Ensure that SQLite.framework is 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.