{"id":42909,"date":"2024-04-23T15:16:14","date_gmt":"2024-04-23T19:16:14","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=42909"},"modified":"2024-04-23T16:46:29","modified_gmt":"2024-04-23T20:46:29","slug":"elegant-concurrency-operations-in-core-data","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2024\/04\/23\/elegant-concurrency-operations-in-core-data\/","title":{"rendered":"Elegant Concurrency Operations in Core Data"},"content":{"rendered":"<p><a href=\"https:\/\/fatbobman.com\/en\/posts\/core-data-reform-achieving-elegant-concurrency-operations-like-swiftdata\/\">Fatbobman<\/a> (<a href=\"https:\/\/mastodon.social\/@fatbobman\/112288723779377382\">Mastodon<\/a>):<\/p>\n<blockquote cite=\"https:\/\/fatbobman.com\/en\/posts\/core-data-reform-achieving-elegant-concurrency-operations-like-swiftdata\/\">\n<p>This article aims to explore how to introduce elegant and safe concurrency operations similar to those of SwiftData into Core Data, implementing a Core Data version of <code>@ModelActor<\/code>.<\/p>\n<p>[&#8230;]<\/p>\n<p>Following the fundamental principles of Core Data concurrency operations, all operations on managed objects must be performed on the thread of their owning context. This restriction means that the <code>Actor<\/code> model cannot be directly applied to Core Data&rsquo;s concurrent operations.<\/p>\n<p>However, the Swift community proposed the concept of custom <code>Actor<\/code> executors through <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0392-custom-actor-executors.md\" target=\"_blank\" rel=\"noopener\">SE-392<\/a>, and this functionality was implemented in Swift 5.9.<\/p>\n\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/03\/01\/how-the-swift-compiler-knows-that-dispatchqueue-main-implies-mainactor\/\">How the Swift Compiler Knows That DispatchQueue.main Implies @MainActor<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/10\/02\/model-for-coredata\/\">@Model for CoreData<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/09\/19\/swift-5-9\/\">Swift 5.9<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/06\/12\/swiftdata\/\">SwiftData<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/05\/12\/mainactor-not-guaranteed\/\">@MainActor Not Guaranteed<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Fatbobman (Mastodon): This article aims to explore how to introduce elegant and safe concurrency operations similar to those of SwiftData into Core Data, implementing a Core Data version of @ModelActor. [&#8230;] Following the fundamental principles of Core Data concurrency operations, all operations on managed objects must be performed on the thread of their owning context. [&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-04-23T19:16:18Z","apple_news_api_id":"0fda21b5-966c-49af-8849-248d36562670","apple_news_api_modified_at":"2024-04-23T20:46:33Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AD9ohtZZsSa-ISSSNNlYmcA","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":[800,109,31,2321,30,2385,941,71,2200,901],"class_list":["post-42909","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-concurrency","tag-coredata","tag-ios","tag-ios-17","tag-mac","tag-macos-14-sonoma","tag-macros","tag-programming","tag-swift-concurrency","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/42909","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=42909"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/42909\/revisions"}],"predecessor-version":[{"id":42911,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/42909\/revisions\/42911"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=42909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=42909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=42909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}