{"id":41717,"date":"2024-01-09T14:48:40","date_gmt":"2024-01-09T19:48:40","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=41717"},"modified":"2024-01-09T14:48:40","modified_gmt":"2024-01-09T19:48:40","slug":"swiftdata-fetching-pending-changes","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2024\/01\/09\/swiftdata-fetching-pending-changes\/","title":{"rendered":"SwiftData Fetching Pending Changes"},"content":{"rendered":"<p><a href=\"https:\/\/useyourloaf.com\/blog\/swiftdata-fetching-pending-changes\/\">Keith Harrison<\/a>:<\/p>\n<blockquote cite=\"https:\/\/useyourloaf.com\/blog\/swiftdata-fetching-pending-changes\/\">\n<p>If you don&rsquo;t want the pending changes included in the fetch results you should be able to override the default by setting <code>includePendingChanges<\/code> to <code>false<\/code> in the fetch descriptor[&#8230;] Unfortunately, I don&rsquo;t seem to be able to get that to work using iOS 17.2 (FB13509125). The pending change is always returned in the results.<\/p>\n<\/blockquote>\n<p>It&rsquo;s interesting that the fetch results are different than with Core Data. It&rsquo;s not clear whether there&rsquo;s a bug with propagating in-memory changes to the managed object or whether SwiftData is using its own predicate evaluation for unsaved objects, leading to different performance characteristics and behavior.<\/p>\n\n<blockquote cite=\"https:\/\/useyourloaf.com\/blog\/swiftdata-fetching-pending-changes\/\"><p>The way pending changes interacts with a fetch limit also seems a little odd with SwiftData. [&#8230;] It seems that SwiftData is including the pending change in the result without taking into account the fetch limit.<\/p><\/blockquote>\n<p>And I don&rsquo;t understand why it&rsquo;s generating SQL with <code>LIMIT 2<\/code> instead of <code>LIMIT 1<\/code>. These bugs where there&rsquo;s no error reported and it silently gives you incorrect results are just awful.<\/p>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/06\/12\/swiftdata\/\">SwiftData<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Keith Harrison: If you don&rsquo;t want the pending changes included in the fetch results you should be able to override the default by setting includePendingChanges to false in the fetch descriptor[&#8230;] Unfortunately, I don&rsquo;t seem to be able to get that to work using iOS 17.2 (FB13509125). The pending change is always returned in 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-01-09T19:48:44Z","apple_news_api_id":"c5c1d8f4-fb92-4935-a637-529132735de1","apple_news_api_modified_at":"2024-01-09T19:48:44Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AxcHY9PuSSTWmN1KRMnNd4Q","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":[131,109,31,2321,30,2385,71,2404],"class_list":["post-41717","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-bug","tag-coredata","tag-ios","tag-ios-17","tag-mac","tag-macos-14-sonoma","tag-programming","tag-swiftdata"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/41717","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=41717"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/41717\/revisions"}],"predecessor-version":[{"id":41718,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/41717\/revisions\/41718"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=41717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=41717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=41717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}