Monday, December 16, 2024

Forked

Drew McCormack (Mastodon):

I’m launching a new Swift framework called Forked for working with shared data, both on a single device, and across many.

[…]

The merging that @ForkedModel provides is pretty powerful. It does property-wise merging of structs, and if you attach the @Merged attribute, you can add your own custom merging logic, or use the advanced algorithms built in (like CRDTs).

To give an example, the notes property above is a String. With @Merged applied, it gets a hidden power — it can resolve conflicts in a more natural way. Rather than discarding one set of changes, or merging to give somewhat arbitrary results, it produces a result a person would likely expect. For example, if we begin with the text “pretty cool”, and change the text to “Pretty Cool” on one device, and to “pretty cool!!!” on another, the merged result result will be “Pretty Cool!!!”. Nuff said.

And this works within your app’s process, between processes (eg with sharing extensions), and even between devices via iCloud.

See also:

Previously:

Comments RSS · Twitter · Mastodon

Leave a Comment