{"id":555729,"date":"2022-02-26T16:48:34","date_gmt":"2022-02-26T08:48:34","guid":{"rendered":"http:\/\/4563.org\/?p=555729"},"modified":"2022-02-26T16:48:34","modified_gmt":"2022-02-26T08:48:34","slug":"%e6%b1%82%e5%8a%a9-%e5%85%b3%e4%ba%8e-swiftui-fetchrequest-nspredicate-%e5%9c%a8%e6%9b%b4%e6%96%b0%e6%95%b0%e6%8d%ae%e4%b9%8b%e5%90%8e%e5%8f%98%e4%b8%ba-nil-%e7%9a%84%e9%97%ae%e9%a2%98-10","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=555729","title":{"rendered":"[\u6c42\u52a9] \u5173\u4e8e SwiftUI @FetchRequest nsPredicate \u5728\u66f4\u65b0\u6570\u636e\u4e4b\u540e\u53d8\u4e3a nil \u7684\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1> [\u6c42\u52a9] \u5173\u4e8e SwiftUI @FetchRequest nsPredicate \u5728\u66f4\u65b0\u6570\u636e\u4e4b\u540e\u53d8\u4e3a nil \u7684\u95ee\u9898 <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : AlwaysBee <\/span>  <span><i><\/i> 49<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u7b80\u5355\u63cf\u8ff0\u4e00\u4e0b\u6211\u8fd9\u91cc\u9047\u5230\u7684\u95ee\u9898\uff1a \u80cc\u666f\uff1a \u4e3b\u9875 Page A \uff0c\u5217\u8868\u9875 Page B \uff0c\u4e24\u4e2a\u9875\u9762\u90fd\u4f1a\u901a\u8fc7 @FetchRequest \u8fd9\u4e2a property wrapper \u83b7\u53d6\u6570\u636e\uff0c\u5e76\u4e14\u662f\u6839\u636e\u65e5\u671f\u4f5c\u4e3a\u8fc7\u6ee4\u6761\u4ef6\uff0cstart_date &gt;= &#8230; and start_date &lt; &#8230;<\/p>\n<pre><code>  @FetchRequest(sortDescriptors: [SortDescriptor(PlanItem.start_time)])   private var plans: FetchedResults&lt;PlanItem&gt;  ....\/\/ \u7701\u7565    self.plans.nsPredicate = NSPredicate(format: \"%K &gt;= %@ AND %K &lt; %@\", #keyPath(PlanItem.start_time), startDate as NSDate,#keyPath(PlanItem.start_time), endDate as NSDate ) <\/code><\/pre>\n<p>\u5f53\u4ece Page A navigate \u5230 Page B \uff0c\u4e14\u6b64\u65f6 Page A \u663e\u793a\u7684\u6570\u636e\u548c Page B \u7684\u6570\u636e\u540c\u4e00\u5929\u7684\uff0c\u4e5f\u5373\u4ed6\u4eec\u7684\u8fc7\u6ee4\u6761\u4ef6\u662f\u4e00\u81f4\u7684\uff0c\u5982\u679c\u6b64\u65f6\u5728 Page B \u6dfb\u52a0\u8be5\u65e5\u671f\u7684\u6570\u636e\u6216\u8005\u66f4\u65b0\u6570\u636e\uff0c\u5219\u4f1a\u5bfc\u81f4\u5217\u51fa\u6240\u6709\u65e5\u671f\u7684\u6570\u636e\u7684\u95ee\u9898\uff0c\u4e5f\u5c31\u662f\u65e5\u671f\u6761\u4ef6\u5931\u6548\u4e86\uff0c\u901a\u8fc7\u6392\u67e5\u53d1\u73b0\u662f nsPredicate \u53d8\u4e3a nil \u4e86\u3002 \u4f46\u5982\u679c\u6211\u6b64\u65f6\u5c06 Page B \u7684\u65e5\u671f\u5207\u6362\u5230\u540e\u4e00\u5929\uff08\u5373\u548c Page A \u7684\u8fc7\u6ee4\u6761\u4ef6\u4e0d\u4e00\u81f4\uff09\uff0c\u8fdb\u884c\u540c\u6837\u7684\u66f4\u65b0\u64cd\u4f5c\uff0c\u5219\u6b63\u5e38\u8fd0\u884c<\/p>\n<p>\u5728\u5b98\u65b9\u8bba\u575b\u627e\u5230\u4e86\u4e00\u4e2a\u8fd1\u4f3c\u7684\u95ee\u9898 https:\/\/developer.apple.com\/forums\/thread\/692040<\/p>\n<p>\u76f8\u5173\uff1a https:\/\/www.raywenderlich.com\/27201015-dynamic-core-data-with-swiftui-tutorial-for-ios<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>2<\/span>) <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"7150947\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hstdt <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> \u6211\u4e00\u822c\u518d\u5c01\u88c5\u4e00\u5c42 View \uff0c\u628a predicate \u4f5c\u4e3a\u53c2\u6570\uff0c\u5728 init \u65b9\u6cd5\u91cc\u9762\u5168\u521d\u59cb\u5316\u6389\uff0c\u4e0d\u4f1a\u518d\u53bb\u4fee\u6539 predicate <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"7150949\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : AlwaysBee <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @hstdt \u662f\u7684\uff0c\u6211\u4e5f\u662f\u8fd9\u4e48\u505a\u7684\u3002<br \/>\u8fd9\u6b21\u7528\u4e86 iOS 15 \u7684\u65b0\u7279\u6027\uff0c\u53ef\u4ee5\u52a8\u6001\u5730\u66f4\u65b0 predicate \uff0c\u5728\u5e16\u5b50\u91cc\u7684\u60c5\u51b5\u4f1a\u51fa\u95ee\u9898 <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>[\u6c42\u52a9] \u5173\u4e8e SwiftUI @&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/555729"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=555729"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/555729\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=555729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=555729"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=555729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}