Hello,
I am currently porting Automerge to swift. It is a CRDT. You can create a document, sync the content to different devices, edit concurrently, sync it back and end up with consistent data on every device. (It is amazing!!!)
Internally it transforms the data heavily and just syncs operations instead of the new state of the document. This requires dynamic information of the data.
When initialising an document I transform a Codable
struct in a dictionary and iterate over all keys, which gives me the required dynamic.
But when modifying the document, I use a swift key path which carries all the static information I need, but lacks the dynamic key path. As a workaround the user of the API needs to pass a string in a similar format of the key path to satisfy the required dynamic.
let trip = Trip(name, "Summer 2020", stops: [])
let document = Automerge.Document(trip)
var mutableDocument = document
mutableDocument.change { doc
doc[\.stops, "stops"].append(Stop(name: "Munich", night: 0))
doc[\.stops, "stops"].append(Stop(name: "Rome", night: 2))
}
mutableDocument.change { doc
doc[\.name, "name"] = "Summer 2021"
doc[\.stops[1].nights, "stops[1].nights"] = 3
}
This works, but obviously comes with some disadvantages.
- Easy to mistype key paths.
- If underlying coding keys are customised, it breaks
- strange looking API, imagine it could be as clear as key path member lookup
I did a lot of research, but could not find a way to get dynamic coding keys of a key path. I am looking for something between dynamic member lookup and keypath member lookup.
I would support such a feature, and would like to help refine it in the future.
Cheers
Lukas
[automerge-swift](GitHub - automerge/automerge-swift: Wrapper around Swift types that can be modified concurrently by different users, and merged again automatically (a CRDT).