{"id":28924,"date":"2020-05-13T15:52:56","date_gmt":"2020-05-13T19:52:56","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=28924"},"modified":"2020-05-13T15:52:56","modified_gmt":"2020-05-13T19:52:56","slug":"nested-property-wrappers-in-swift","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2020\/05\/13\/nested-property-wrappers-in-swift\/","title":{"rendered":"Nested Property Wrappers in Swift"},"content":{"rendered":"<p><a href=\"https:\/\/noahgilmore.com\/blog\/nesting-property-wrappers\/\">Noah Gilmore<\/a>:<\/p>\n<blockquote cite=\"https:\/\/noahgilmore.com\/blog\/nesting-property-wrappers\/\"><p>The <a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0258-property-wrappers.md#composition-of-property-wrappers\">Swift Evolution Proposal<\/a> details how composition of property wrappers works - the <code>wrappedValue<\/code> access goes two levels deep.<\/p><\/blockquote><p>They work inside out, like Python decorators, but with more ceremony from the type system.<\/p><blockquote cite=\"https:\/\/noahgilmore.com\/blog\/nesting-property-wrappers\/\"><p>The <code>wrappedValue<\/code> of the outer property wrapper isn&rsquo;t <code>String<\/code>, it&rsquo;s actually <code>Appending<\/code>, and therein lies the problem. If we want one level of wrapping, <code>Appending<\/code> needs to take a <code>String<\/code>, but for two levels of wrapping it needs to take another <code>Appending<\/code>.<\/p><p>This might seem like a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Catch-22_(logic)\">Catch-22<\/a>, but we can actually use <em>protocolization<\/em> to solve this issue. Instead of <code>Appending<\/code> operating on <code>Strings<\/code>, we can make it operate on &ldquo;anything that is appendable&rdquo; by using a protocol.<\/p><\/blockquote>\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2019\/06\/25\/swift-property-wrappers\/\">Swift Property Wrappers<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Noah Gilmore: The Swift Evolution Proposal details how composition of property wrappers works - the wrappedValue access goes two levels deep.They work inside out, like Python decorators, but with more ceremony from the type system.The wrappedValue of the outer property wrapper isn&rsquo;t String, it&rsquo;s actually Appending, and therein lies the problem. If we want one [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2020-05-13T19:52:59Z","apple_news_api_id":"cfcf7490-ff87-4606-bd46-a13d3a4e704f","apple_news_api_modified_at":"2020-05-13T19:52:59Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/Az890kP-HRga9RqE9Ok5wTw","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":[46,71,901],"class_list":["post-28924","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28924","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=28924"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28924\/revisions"}],"predecessor-version":[{"id":28925,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28924\/revisions\/28925"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=28924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=28924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=28924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}