{"id":45163,"date":"2024-09-30T14:53:05","date_gmt":"2024-09-30T18:53:05","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=45163"},"modified":"2024-09-30T14:53:05","modified_gmt":"2024-09-30T18:53:05","slug":"swiftdata-expressions","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2024\/09\/30\/swiftdata-expressions\/","title":{"rendered":"SwiftData Expressions"},"content":{"rendered":"<p><a href=\"https:\/\/useyourloaf.com\/blog\/swiftdata-expressions\/\">Keith Harrison<\/a>:<\/p>\n<blockquote cite=\"https:\/\/useyourloaf.com\/blog\/swiftdata-expressions\/\">\n<p>In iOS 18, SwiftData can make use of Foundation&rsquo;s new <code>#Expression<\/code> macro to make it easier to build more complex predicates. From the WWDC session:<\/p>\n<blockquote>\n<p>Expressions allow for reference values that do not produce true or false but instead allow for arbitrary types.<\/p>\n<\/blockquote>\n<p>You can then evaluate the expression as part of more complex predicate.<\/p>\n<p>[&#8230;]<\/p>\n<p>If you expand the expression macro or check the <a href=\"https:\/\/developer.apple.com\/documentation\/foundation\/expression\">Expression documentation<\/a> you&rsquo;ll see it&rsquo;s creating <a href=\"https:\/\/developer.apple.com\/documentation\/foundation\/predicateexpression\">PredicateExpressions<\/a> which appear to support a wide range of methods. Unfortunately I can&rsquo;t seem to get most of them to work either in predicates or expressions.<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/09\/27\/nsmanagedobjectid-and-persistentidentifier\/\">NSManagedObjectID and PersistentIdentifier<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/07\/26\/swiftdata-and-core-data-at-wwdc24\/\">SwiftData and Core Data at WWDC24<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/05\/28\/dynamic-swift-predicates-in-macos-14-and-ios-17\/\">Dynamic Swift Predicates in macOS 14 and iOS 17<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Keith Harrison: In iOS 18, SwiftData can make use of Foundation&rsquo;s new #Expression macro to make it easier to build more complex predicates. From the WWDC session: Expressions allow for reference values that do not produce true or false but instead allow for arbitrary types. You can then evaluate the expression as part of more [&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-09-30T18:53:09Z","apple_news_api_id":"7131e1af-15c4-4f4e-bae5-823b132d7c49","apple_news_api_modified_at":"2024-09-30T18:53:09Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AcTHhrxXET0665YI7Ey18SQ","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":[109,31,2586,30,2598,71,2404],"class_list":["post-45163","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-coredata","tag-ios","tag-ios-18","tag-mac","tag-macos-15-sequoia","tag-programming","tag-swiftdata"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/45163","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=45163"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/45163\/revisions"}],"predecessor-version":[{"id":45164,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/45163\/revisions\/45164"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=45163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=45163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=45163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}