Automerge

0.5.12

Swift language bindings presenting Automerge
automerge/automerge-swift

What's New

0.5.12

2024-04-04T18:03:30Z

BREAKING CHANGES

This release resolves a cross-platform representation mismatch of Dates (the Automerge .timestamp scalar value), documented at #139. When I implemented the swift overlay, I missed that the Int64 value stored was in milliseconds, instead of seconds, so the date conversions for cross-platform were being incorrectly interpreted.

The effect of this is that dates from other platforms were interpretted incorrectly. Now with the fix, dates you have in existing Automerge documents that were created with earlier versions of this swift framework will be incorrect, as they were stored with the expectations of seconds since epoch rather than milliseonds since epoch. If you're using any timestamps/dates in your models, the workaround to fix previously encoded data is to read the raw scalar value from the document and multiply or divide the value (depending on which way you're going) by 1000 to get to a corrected value.

What's Changed

New Contributors

Full Changelog: 0.5.11...0.5.12

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.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.

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Apr 26 2024 07:37:29 GMT-0900 (Hawaii-Aleutian Daylight Time)