{"id":325930,"date":"2021-02-03T08:18:11","date_gmt":"2021-02-03T00:18:11","guid":{"rendered":"http:\/\/4563.org\/?p=325930"},"modified":"2021-02-03T08:18:11","modified_gmt":"2021-02-03T00:18:11","slug":"%e8%af%b7%e6%95%99%ef%bc%9a-appstorage-%e7%9a%84%e8%ae%be%e7%bd%ae%ef%bc%8c%e6%80%8e%e4%b9%88%e9%87%8d%e7%bd%ae-%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=325930","title":{"rendered":"\u8bf7\u6559\uff1a AppStorage \u7684\u8bbe\u7f6e\uff0c\u600e\u4e48\u91cd\u7f6e \uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u6559\uff1a AppStorage \u7684\u8bbe\u7f6e\uff0c\u600e\u4e48\u91cd\u7f6e \uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ericgui <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u6211\u5728 AppStorage \u91cc\uff0c\u6709\u4e00\u4e2a\u53d8\u91cf\uff0c\u503c\u4e3a true\uff0c\u7b2c\u4e00\u6b21\u70b9\u51fb\u6309\u94ae\u4e4b\u540e\uff0c\u5c31\u53d8\u4e3a false<\/p>\n<p>\u7ed3\u679c\u6bcf\u6b21\u91cd\u65b0 build \u4e4b\u540e\uff0c\u8fd9\u4e2a\u503c\u5c31\u6c38\u8fdc\u4e3a false \u4e86<\/p>\n<p>\u76ee\u524d\u53ea\u597d\u5728 emulator \u91cc\uff0c\u628a app \u5220\u4e86\uff0c\u91cd\u65b0 run \u4e00\u4e0b<\/p>\n<p>\u6709\u4ec0\u4e48\u529e\u6cd5\u4ec5\u4ec5\u91cd\u7f6e AppStorage \u800c\u4e0d\u7528\u5220 app \uff1f \u8c22\u8c22      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>6<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5215886\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : AllenChiangCN <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fdb app info\uff0c\u7136\u540e clear storage                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5215887\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : AllenChiangCN <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @AllenChiangCN \u4e0d\u597d\u610f\u601d\uff0c\u4f60\u597d\u50cf\u8bf4\u7684\u662f iOS                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5215888\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ericgui <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @AllenChiangCN \u662f iOS\uff0c\u4e0d\u597d\u610f\u601d\u6ca1\u8bf4\u6e05\u695a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5215889\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JasonEWNL <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6807\u8bb0\u4e3a AppStorage \u7684\u53d8\u91cf\u672c\u5730\u5b58\u7740, run \u4e4b\u540e\u5c31\u50cf\u5e38\u89c4\u8986\u76d6\u5b89\u88c5\u540e\u6301\u7eed\u4fdd\u5b58\u7684\u7528\u6237\u6570\u636e\u4e00\u6837.<\/p>\n<p>\u65b9\u6848\u4e00: \u8bbe\u7f6e\u4e3a State, \u5c0f\u91cf\u53ef\u5728\u6253\u5305\u524d\u624b\u52a8\u6539\u56de, \u5982\u679c\u6bd4\u8f83\u91cd\u5ea6\u5efa\u8bae\u8bbe\u7f6e\u9884\u5904\u7406\u8bed\u53e5.<\/p>\n<p>&#8220;`swift<br \/>#if DEBUG<br \/> @State &#8230;<br \/>#else<br \/> @AppStorage &#8230;<br \/>#endif<br \/>&#8220;`<\/p>\n<p>\u65b9\u6848\u4e8c: \u53c2\u8003 Stack Overflow \u7684\u4e00\u4e2a\u4e2a\u66f2\u7ebf\u65b9\u6848 (\u9488\u5bf9\u6a21\u62df\u5668\u7684\u5728\u8bc4\u8bba\u91cc): https:\/\/stackoverflow.com\/questions\/15258777\/xcode-delete-application-before-running-on-device#answer-32992734<\/p>\n<p>\u7b80\u5355\u89e3\u91ca\u5c31\u662f\u628a `xcrun simctl uninstall sim-udid bundle-id` \u653e\u5728 build \u811a\u672c\u91cc, \u6bcf\u6b21 build \u4f1a\u5148\u5220\u6389\u5e94\u7528.                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5215890\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ericgui <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @JasonEWNL \u8c22\u8c22<br \/>\u4e5f\u5c31\u662f\u8bf4\uff0c\u5176\u5b9e\u6ca1\u529e\u6cd5\u907f\u514d\u5220\u9664 app \u8fd9\u4e2a\u6b65\u9aa4\u3002\u3002\u3002\u3002\u65e0\u975e\u662f\u624b\u52a8\u8fd8\u662f\u7528\u811a\u672c\u547d\u4ee4                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5215891\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JasonEWNL <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ericgui \u662f\u7684. \u56e0\u4e3a\u4e0d\u5220\u9664\u5730\u5728 Xcode \u91cc run \u4e00\u6b21, \u5c31\u50cf\u7528\u6237\u4e0d\u5220\u9664\u5e94\u7528\u5c31\u4ece App Store \u66f4\u65b0\u4e00\u6837, \u6807\u8bb0\u4e3a AppStorage \u7684\u53d8\u91cf\u5b58\u50a8\u5728 UserDefaults \u91cc, \u5982\u5176\u4ed6\u6c38\u4e45\u5b58\u50a8\u65b9\u6848\u4e00\u6837, \u4ec5\u80fd\u901a\u8fc7\u7528\u6237\u64cd\u4f5c (\u5305\u62ec\u5220\u9664\u5728\u5185) \u624d\u80fd\u4fee\u6539\u6216\u91cd\u7f6e.<\/p>\n<p>\u4e0d\u8fc7\u8fd9\u4e48\u4e00\u8bf4\u5c31\u60f3\u5230\u65b9\u6848\u4e09: \u7ed9\u6807\u8bb0\u4e3a AppStorage \u7684\u53d8\u91cf\u6240\u5728 View \u7684 body \u8bbe\u7f6e onAppear, \u7c7b\u4f3c\u65b9\u6848\u4e00\u5730\u8fdb\u884c\u9884\u5904\u7406.<\/p>\n<p>&#8220;`swift<br \/>@AppStorage &#8230;<\/p>\n<p>var body: some View {<br \/> &#8230;<br \/>}<br \/>.onAppear {<br \/> #if DEBUG<br \/> &#8230; = DEBUG_VALUE<br \/> #endif<br \/>}<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u6559\uff1a AppStorage \u7684\u8bbe&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/325930"}],"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=325930"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/325930\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=325930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=325930"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=325930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}