A Objective-C++ wrapper for leveldb.
Package.swift
(you can also use SPM from Xcode)
let package = Package(
name: "Demo",
platforms: [
.macOS(.v12),
.iOS(.v12)
],
products: [
.executable(name: "demo", targets: ["Demo"]),
],
dependencies: [
.package(url: "https://github.com/yechentide/LvDBWrapper", branch: "main")
],
targets: [
.executableTarget(name: "Demo", dependencies: [
.product(name: "LvDBWrapper", package: "LvDBWrapper")
]),
]
)
import & use
import LvDBWrapper
guard let db = LvDB(dbPath: "db-dir-path") else { ... }
let wellKnownKey = "~local_player".data(using: .utf8)!
db.seek(wellKnownKey)
guard let key = db.key(), let value = db.value() else { return }
var firstToLastCount = 0
db.seekToFirst()
while db.valid() {
firstToLastCount += 1
db.next()
}
This package wrapped 2 kind of c++ libraries: libz & libleveldb.
Each xcframework contains 3 static .a files for iOS(arm64), MacOS(arm64), Simulator(arm64).
iOS(arm64) | MacOS(arm64) | MacOS(x86) | Simulator(arm64) | Simulator(x86) | |
---|---|---|---|---|---|
libz.xcframework | ✔︎ | ✔︎ | ✔︎ | ✔︎ | × |
libleveldb.xcframework | ✔︎ | ✔︎ | ✔︎ | ✔︎ | × |
For MacOS projects, you can use this package directly.
For iOS projects, you need to do some additional work.
The static libraries for iOS platform, are built with my personal apple team account.
Maybe my account will expire some day and I can't and won't offer any guarantees.
So if your projects is for iOS, you must rebuild libz.a and libleveldb.a for iOS.
In this case, please replace the following files:
frameworks/libz.xcframework/ios-arm64/libz.a
frameworks/libleveldb.xcframework/ios-arm64/libleveldb.a
Just run the script and add teams or change the minimum version when needed. It's so easy!
git clone https://github.com/yechentide/LvDBWrapper.git
cd LvDBWrapper/scripts
chmod u+x build.sh
./build.sh
After you get the xcframeworks, you can fork this repository, and swap xcframeworks in frameworks
directory.