{"id":46168,"date":"2024-12-16T14:19:32","date_gmt":"2024-12-16T19:19:32","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=46168"},"modified":"2024-12-16T14:19:32","modified_gmt":"2024-12-16T19:19:32","slug":"forked","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2024\/12\/16\/forked\/","title":{"rendered":"Forked"},"content":{"rendered":"<p><a href=\"https:\/\/appdecentral.com\/2024\/12\/13\/now-we-are-all-forked\/\">Drew McCormack<\/a> (<a href=\"https:\/\/mastodon.cloud\/@drewmccormack\/113647245934319726\">Mastodon<\/a>):<\/p>\n<blockquote cite=\"https:\/\/appdecentral.com\/2024\/12\/13\/now-we-are-all-forked\/\"><p>I&rsquo;m launching a new Swift framework called <a href=\"https:\/\/github.com\/drewmccormack\/Forked\">Forked<\/a> for working with shared data, both on a single device, and across many.<\/p><p>[&#8230;]<\/p><p>The merging that <code>@ForkedModel<\/code> provides is pretty powerful. It does property-wise merging of structs, and if you attach the <code>@Merged<\/code> attribute, you can add your own custom merging logic, or use the advanced algorithms built in (like CRDTs).<\/p><p>To give an example, the <code>notes<\/code> property above is a <code>String<\/code>. With <code>@Merged<\/code> applied, it gets a hidden power &mdash; 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 &ldquo;pretty cool&rdquo;, and change the text to &ldquo;Pretty Cool&rdquo; on one device, and to &ldquo;pretty cool!!!&rdquo; on another, the merged result result will be &ldquo;Pretty Cool!!!&rdquo;. Nuff said.<\/p><p>And this works within your app&rsquo;s process, between processes (<em>eg<\/em> with sharing extensions), and even between devices via iCloud.<\/p><\/blockquote>\n\n<p>See also:<\/p>\n<ul>\n<li><a href=\"https:\/\/josephg.com\/blog\/crdts-are-the-future\/\">CRDTs are the future<\/a> (via <a href=\"https:\/\/news.ycombinator.com\/item?id=24617542\">Hacker News<\/a>)<\/li>\n<li><a href=\"https:\/\/josephg.com\/blog\/crdts-go-brrr\/\">5000x faster CRDTs<\/a> (via <a href=\"https:\/\/news.ycombinator.com\/item?id=28017204\">Hacker News<\/a>)<\/li>\n<li><a href=\"https:\/\/martin.kleppmann.com\/papers\/bft-crdt-papoc22.pdf\">Making CRDTs Byzantine Fault Tolerant<\/a> (via <a href=\"https:\/\/news.ycombinator.com\/item?id=30560573\">Hacker News<\/a>)<\/li>\n<\/ul>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/07\/22\/a-first-replicating-type\/\">A First Replicating Type<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2019\/06\/04\/syncing-core-data-with-cloudkit-and-nspersistentcloudkitcontainer\/\">Syncing Core Data With CloudKit and NSPersistentCloudKitContainer<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2013\/10\/02\/core-data-ensembles\/\">Core Data Ensembles<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Drew McCormack (Mastodon): I&rsquo;m launching a new Swift framework called Forked for working with shared data, both on a single device, and across many.[&#8230;]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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2024-12-16T19:19:34Z","apple_news_api_id":"f81ff931-9982-4238-bce8-1be2ee74aab9","apple_news_api_modified_at":"2024-12-16T19:19:34Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/A-B_5MZmCQji86Bvi7nSquQ","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[1615,916,800,2704,31,2586,30,2598,941,74,71,1774,2200,901,269],"class_list":["post-46168","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-agenda","tag-cloudkit","tag-concurrency","tag-forked","tag-ios","tag-ios-18","tag-mac","tag-macos-15-sequoia","tag-macros","tag-opensource","tag-programming","tag-swift-codable","tag-swift-concurrency","tag-swift-programming-language","tag-syncing"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/46168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=46168"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/46168\/revisions"}],"predecessor-version":[{"id":46169,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/46168\/revisions\/46169"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=46168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=46168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=46168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}