This repo is a Swift Package Manager (SPM) package to make it easier to use Graft within Swift projects.
Follow these steps to add libgraft.swift
to your Xcode project using Swift Package Manager:
-
Open your Xcode project.
-
Go to
File
>Add Package Dependencies...
-
Enter the repository URL for
libgraft.swift
in the search bar (top right):https://github.com/orbitinghail/libgraft.swift.git
-
Select the version you want to use (usually the latest).
-
Click "Add Package".
-
Add the libgraft "Package Product" to your application target on the next screen.
-
Import and initialize the library during application startup:
// first, you need to import libgraft import libgraft
// then add this to your application startup process // this example assumes you are using GRDB for SQLite let fm = FileManager.default let supportDir = try fm.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true) let configPath = supportDir.appendingPathComponent("graft-config.toml") let dataPath = supportDir.appendingPathComponent("data") // write out a libgraft config file and set the GRAFT_CONFIG env variable let config = """ data_dir = "\(dataPath.path)" autosync = false make_default = true """ try config.write(to: configPath, atomically: true, encoding: .utf8) setenv("GRAFT_CONFIG", configPath.path, 1) // Initialize graft let tempDB = try DatabaseQueue() _ = tempDB.inDatabase { db in libgraft.graft_static_init(db.sqliteConnection) } // Open real DB with random Volume ID let db = try DatabaseQueue(path: "random")