The Swift binding depends on the C binding to OpenDAL. Before using this package, you need to build the C library first:
cd bindings/swift
make build-c
To check whether the package is ready to use, simply run the test:
make test
The package manifest is not located at the root directory of its repository. To use it, add the path of this package to the Package.swift
manifest of your project:
// swift-tools-version:5.7
import PackageDescription
let package = Package(
name: "MyTool",
dependencies: [
.package(path: "/path/to/opendal/bindings/swift/OpenDAL"),
],
targets: [
.target(name: "MyTool", dependencies: [
.product(name: "OpenDAL", package: "OpenDAL"),
]),
]
)
The demo below shows how to write a key to the memory storage, and read it back:
import OpenDAL
// Create an operator with `memory` backend.
let op = try Operator(scheme: "memory")
// Write some data into path `/demo`.
let someData = Data([1, 2, 3, 4])
try op.blockingWrite(someData, to: "/demo")
// Read the data back.
let readData = try op.blockingRead("/demo")
// You can use the read data here.
print(readData!)