Skip to content

automerge/automerge-swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

74b5798 · Feb 10, 2025
Feb 2, 2025
Jul 29, 2023
Feb 2, 2025
Aug 16, 2024
Feb 10, 2025
Feb 2, 2025
Oct 26, 2024
Dec 11, 2023
Feb 2, 2025
Oct 26, 2024
Oct 26, 2024
May 25, 2023
May 27, 2023
Mar 8, 2023
Mar 8, 2023
May 25, 2024
May 21, 2023
Jan 24, 2025
May 30, 2024

Repository files navigation

Automerge-swift

The project is an Automerge implementation, a library of data structures for building collaboraative applications, in Swift. Automerge is cross platform and cross-language, allowing you to provide collaboration support between browsers and native apps.

The API Documentation provides an overview of this library and how to use it.

Automerge Repo (Swift) is a supplemental library that extends this library. It adds pluggable network and storage support for Apple platforms for a more "batteries included" result, and is tested with the JavaScript version of Automerge Repo.

The open-source iOS and macOS document-based SwiftUI App MeetingNotes provides a show-case for how to use Automerge to build a live, collaborative experience. MeetingNotes builds over both this library and the repository to provide both WebSocket and peer to peer based networking in the app.

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.5.2")
    ],
    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, value: .String("blue"))
try! doc.insert(obj: list, index: 1, value: .String("red"))

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

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

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

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

Note: There was an earlier project that provided Swift language bindings for Automerge. The repository was renamed and archived, but is available if you are looking for it.