{"id":47571,"date":"2025-05-01T15:36:44","date_gmt":"2025-05-01T19:36:44","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=47571"},"modified":"2025-05-01T15:36:44","modified_gmt":"2025-05-01T19:36:44","slug":"swift-proposal-weak-let","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2025\/05\/01\/swift-proposal-weak-let\/","title":{"rendered":"Swift Proposal: weak let"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0481-weak-let.md\">SE 0481<\/a>:<\/p>\n<blockquote cite=\"https:\/\/github.com\/swiftlang\/swift-evolution\/blob\/main\/proposals\/0481-weak-let.md\"><p>Currently, Swift classes with weak stored properties cannot be <code>Sendable<\/code>, because weak properties have to be mutable, and mutable properties are not allowed in <code>Sendable<\/code> classes[&#8230;]<\/p><p>[&#8230;]<\/p><p>In fact, wrapping weak references in a single-property <code>struct<\/code> is a viable workaround to the <code>var<\/code> restriction in both properties and captures[&#8230;] The existence of this simple workaround is itself an argument that the prohibition of <code>weak let<\/code> is not enforcing some fundamentally important rule.<\/p><p>[&#8230;]<\/p><p>An explicit <code>weak<\/code> capture is now immutable under this proposal, like any other explicit capture. If the programmer really needs a mutable capture, they must capture a separate <code>weak var<\/code>.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>SE 0481: Currently, Swift classes with weak stored properties cannot be Sendable, because weak properties have to be mutable, and mutable properties are not allowed in Sendable classes[&#8230;][&#8230;]In fact, wrapping weak references in a single-property struct is a viable workaround to the var restriction in both properties and captures[&#8230;] The existence of this simple workaround [&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":"2025-05-01T19:36:47Z","apple_news_api_id":"92a7c253-96e7-4155-9b7a-22b63f78823b","apple_news_api_modified_at":"2025-05-01T19:36:47Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AkqfCU5bnQVWbeiK2P3iCOw","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,2200,901],"class_list":["post-47571","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-programming","tag-swift-concurrency","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/47571","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=47571"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/47571\/revisions"}],"predecessor-version":[{"id":47572,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/47571\/revisions\/47572"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=47571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=47571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=47571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}