Skip to content

Commit bc8677d

Browse files
committed
feat(docs): add Swift package integration instructions
1 parent 4c1f554 commit bc8677d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,29 @@ Download the appropriate pre-built binary for your platform from the official [R
120120

121121
You can download the WebAssembly (WASM) version of SQLite with the SQLite Sync extension enabled from: https://www.npmjs.com/package/@sqliteai/sqlite-wasm
122122

123+
### Swift Package
124+
125+
You can [add this repository as a package dependency to your Swift project](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app#Add-a-package-dependency). After adding the package, you'll need to set up SQLite with extension loading by following steps 4 and 5 of [this guide](https://github.com/sqliteai/sqlite-extensions-guide/blob/main/platforms/ios.md#4-set-up-sqlite-with-extension-loading).
126+
127+
Here's an example of how to use the package:
128+
```swift
129+
import CloudSync
130+
131+
...
132+
133+
var db: OpaquePointer?
134+
sqlite3_open(":memory:", &db)
135+
sqlite3_enable_load_extension(db, 1)
136+
var errMsg: UnsafeMutablePointer<Int8>? = nil
137+
sqlite3_load_extension(db, CloudSync.path, nil, &errMsg)
138+
var stmt: OpaquePointer?
139+
sqlite3_prepare_v2(db, "SELECT cloudsync_version()", -1, &stmt, nil)
140+
defer { sqlite3_finalize(stmt) }
141+
sqlite3_step(stmt)
142+
log("cloudsync_version(): \(String(cString: sqlite3_column_text(stmt, 0)))")
143+
sqlite3_close(db)
144+
```
145+
123146
### Loading the Extension
124147

125148
```sql

0 commit comments

Comments
 (0)