Thursday, May 1, 2025

Swift Proposal: weak let

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[…]

[…]

In fact, wrapping weak references in a single-property struct is a viable workaround to the var restriction in both properties and captures[…] The existence of this simple workaround is itself an argument that the prohibition of weak let is not enforcing some fundamentally important rule.

[…]

An explicit weak 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 weak var.

1 Comment RSS · Twitter · Mastodon


Katamari Damacy is not a good model for a programming language.

Leave a Comment