Skip to content

lightsprint09/automerge-swift

 
 

Repository files navigation

Automerge-swift

An Automerge implementation for swift.

This is a low-level library with few concessions to ergonomics, meant to interact directly with the low-level Automerge API. Additional API that is more ergonomic is being added into the repository as this project evolves.

Automerge-Swift API Documentation is available on the Automerge site. A command-line demonstration application (contaaacts) is available that shows using the lower level API.

Note: There was an earlier Swift language bindings for Automerge here at automerge/automerge-swift. The repository was renamed and archived, but is available if you are looking for it.

Quickstart

Add a dependency in Package.swift, as the following example shows:

let package = Package(
    ...
    dependencies: [
        ...
        .package(url: "https://github.com/automerge/automerge-swift.git", from: "0.1.1")
    ],
    targets: [
        .executableTarget(
            ...
            dependencies: [.product(name: "Automerge", package: "automerge-swift")],
            ...
        )
    ]
)

Now you can create a document and do all sorts of Automerge things with it

let doc = Document()
let list = try! doc.putObject(obj: ObjId.ROOT, key: "colours", ty: .List)
try! doc.insert(obj: list, index: 0, .String("blue"))
try! doc.insert(obj: list, index: 1, .String("red"))

let doc2 = doc.fork()
try! doc2.insert(obj: list, index: 0, .String("green"))

try! doc.delete(obj: list, index: 0)

try! doc.merge(doc2) // `doc` now contains {"colours": ["green", "red"]}

For more details on the API, see the Automerge-swift API documentation and the articles within.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 87.4%
  • Rust 6.9%
  • C 3.3%
  • Shell 2.4%