{"id":4828,"date":"2023-04-26T15:09:12","date_gmt":"2023-04-26T06:09:12","guid":{"rendered":"https:\/\/redwing.moo.jp\/cocoa\/?p=4828"},"modified":"2023-04-26T15:16:54","modified_gmt":"2023-04-26T06:16:54","slug":"swiftui%e3%81%ae%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab%e3%82%b3%e3%83%bc%e3%83%89%e3%81%a7%e6%b0%97%e3%81%a5%e3%81%84%e3%81%9f%e7%82%b9%e3%82%92%e3%83%a1%e3%83%a2","status":"publish","type":"post","link":"https:\/\/redwing.moo.jp\/cocoa\/archives\/4828","title":{"rendered":"SwiftUI\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u6c17\u3065\u3044\u305f\u70b9\u3092\u30e1\u30e2"},"content":{"rendered":"\n<p>\u65b0\u3057\u3044\u6280\u8853\u306b\u3064\u3044\u3066\u306f\u3001\u5fc5\u8981\u306b\u8feb\u308c\u3089\u308c\u308b\u3053\u3068\u304c\u306a\u3044\u9650\u308a\u3001\u4f53\u7cfb\u7acb\u3066\u305f\u77e5\u8b58\u306e\u6574\u7406\u304c\u3067\u304d\u3066\u3044\u307e\u305b\u3093\u3002\u3042\u307e\u308a\u5229\u7528\u3057\u306a\u3044\u6280\u8853\u306b\u3064\u3044\u3066\u306f\u3059\u3050\u5fd8\u308c\u3066\u3057\u307e\u3046\u306e\u3067\u3059\u3002<strong>(\u7b11)<\/strong><br>SwiftUI\u306b\u3064\u3044\u3066\u3082\u6570\u5e74\u524d\u304b\u3089\u3001\u8abf\u3079\u3066\u306f\u5fd8\u308c\u3066\u3092\u7e70\u308a\u8fd4\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u518d\u5ea6\u3001\u8abf\u3079\u308b\u969b\u306b\u30e1\u30e2\u304c\u3042\u308b\u3068\u65e9\u304f\u601d\u3044\u51fa\u305b\u308b\u3088\u3046\u306a\u306e\u3067\u3001\u4eca\u56de\u3082\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u3010PropertyWrapper\u306e\u5185\u90e8\u5909\u6570\u306b\u30a2\u30af\u30bb\u30b9\u3011<\/h2>\n\n\n\n<p>PropertyWrapper\u3092\u5b9a\u7fa9\u3057\u305f\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u300c_\u300d\u3092\u3064\u3051\u308b\u3053\u3068\u3067\u3001PropertyWrapper\u306e\u5185\u90e8\u5909\u6570\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3002<br>\uff08ObjC\u306e\u30e1\u30f3\u30d0\u5909\u6570\u306e\u8868\u8a18\u306b\u4f3c\u3066\u3044\u308b\u306e\u3067\u62b5\u6297\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u9593\u9055\u3044\u307f\u305f\u3044\u3067\u306f\u306a\u3044\u306e\u3067\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059\u3002\uff09<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: swift; title: ; notranslate\" title=\"\">\n@Binding var isPresented: Bool\n\ninit(isPresented: Binding) {\n    self._isPresented = isPresented\n}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u3010$ \u3068 projectedValue\u3011<\/h2>\n\n\n\n<p>\u300c$\u300d\u3092\u3064\u3051\u308b\u3068\u5c04\u5f71\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3002\u307e\u305f\u3001\u5185\u90e8\u5909\u6570(_\u3092\u3064\u3051\u305f\u5909\u6570)\u304b\u3089 projectedValue \u3068\u3044\u3046\u30d7\u30ed\u30d1\u30c6\u30a3\u3078\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306e\u3068\u7b49\u4fa1\u306b\u306a\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n_isPresented.projectedValue\n\n$isPresented\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u3010SwiftUI Non-constant range \u8b66\u544a\u3011<\/h2>\n\n\n\n<p>\u300c<code>Non-constant range: argument must be an integer literal<\/code>\u300d\u3068\u3044\u3046 warning \u304c\u51fa\u529b\u3055\u308c\u308b\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u69d8\u306b\u5bfe\u51e6\u3067\u304d\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nForEach(0 ..&amp;lt; myArray.count) { index in\n    ...\n}\n\t\u2193\nForEach(0 ..&amp;lt; myArray.count, id: \\.self) { index in\n    ...\n}\n\n<\/pre><\/div>\n\n\n<p>\u53c2\u8003\uff1a<a href=\"https:\/\/blog.hikaru.run\/2022\/06\/07\/swiftui-foreach-warning.html\" target=\"_blank\" rel=\"noreferrer noopener\">SwiftUI ForEach\u306eNon-constant range\u8b66\u544a<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u3010KeyPath \u306e\u5229\u7528\u3011<\/h2>\n\n\n\n<p>List \u306a\u3069\u4f5c\u6210\u3059\u308b\u5834\u5408\u306b\u8868\u793a\u30c7\u30fc\u30bf\u3092\u4ee5\u4e0b\u306e\u69d8\u306a DataModel \u3067\u8868\u73fe\u3057\u305f\u5834\u5408\u3001\u521d\u671f\u5316\u30d1\u30e9\u30e1\u30fc\u30bf\u306b KeyPath \u3092\u5229\u7528\u3057\u305f\u8a18\u8ff0\u304c\u3067\u304d\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nstruct DataModel: Identifiable {\n    let id = UUID()\n    let name: String\n    var subItems: &#x5B;DataModel]?\n}\n\n  init(\n    data: Data,\n    children: KeyPath&amp;lt;Data.Element, Data?&gt;\n\t:\n\t\u7701\u7565\n\t:\n\n\/\/ \u30d1\u30e9\u30e1\u30fc\u30bf\u6307\u5b9a\u6642\u306b\u306f\u4ee5\u4e0b\u306e\u69d8\u306b KeyPath \u3092\u7528\u3044\u3066\u8a18\u8ff0\u3067\u304d\u308b\nchildren: \\.subItems\n<\/pre><\/div><a href=\"https:\/\/twitter.com\/redwing1300?ref_src=twsrc%5Etfw\" class=\"twitter-follow-button\" data-size=\"large\" data-show-count=\"false\">Follow @redwing1300<\/a><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content --><div id=\"redwi-3379508889\" class=\"redwi- redwi-entity-placement\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-9652476346722993\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:block;\" data-ad-client=\"ca-pub-9652476346722993\" \ndata-ad-slot=\"\" \ndata-ad-format=\"auto\"><\/ins>\n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>\u65b0\u3057\u3044\u6280\u8853\u306b\u3064\u3044\u3066\u306f\u3001\u5fc5\u8981\u306b\u8feb\u308c\u3089\u308c\u308b\u3053\u3068\u304c\u306a\u3044\u9650\u308a\u3001\u4f53\u7cfb\u7acb\u3066\u305f\u77e5\u8b58\u306e\u6574\u7406\u304c\u3067\u304d\u3066\u3044\u307e\u305b\u3093\u3002\u3042\u307e\u308a\u5229\u7528\u3057\u306a\u3044\u6280\u8853\u306b\u3064\u3044\u3066\u306f\u3059\u3050\u5fd8\u308c\u3066\u3057\u307e\u3046\u306e\u3067\u3059\u3002(\u7b11)SwiftUI\u306b\u3064\u3044\u3066\u3082\u6570\u5e74\u524d\u304b\u3089\u3001\u8abf\u3079\u3066\u306f\u5fd8\u308c\u3066\u3092\u7e70\u308a\u8fd4\u3057\u3066\u3044\u308b\u306e &hellip; <a href=\"https:\/\/redwing.moo.jp\/cocoa\/archives\/4828\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46,116],"tags":[301],"class_list":["post-4828","post","type-post","status-publish","format-standard","hentry","category-ios","category-swift","tag-swiftui"],"_links":{"self":[{"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/posts\/4828","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/comments?post=4828"}],"version-history":[{"count":9,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/posts\/4828\/revisions"}],"predecessor-version":[{"id":4838,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/posts\/4828\/revisions\/4838"}],"wp:attachment":[{"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/media?parent=4828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/categories?post=4828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/tags?post=4828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}