Support for [weak self]?

Hi, targeting Android it’s a bit tricky that weak var is treated as a strong reference and [weak self] doesn’t compile. It looks like I’m going to need to manage WeakReference instances myself. I did a search and saw that [weak self] support was logged some time ago as #78119: Problem for existing code in Swift (Data, Operators)

Do you know if this is on the roadmap for a fix any time soon? Thanks!

it’s on the list, but it would only affect ARC based platforms anyways. Android uses GC, so weak is ignored/not used there.

IMO on Android the ideal behaviour would be to create a WeakReference under the hood, whose get() should correspond directly to the optional binding in swift. It is sometimes necessary to avoid circular references in GC, which is why I am about to implement it manually. Up to you of course but I would find it very useful. Cheers!

the android gc doesn’t care about circular references. So really what’s weak in ARC (which is what’s needed to get it to be freed at all) acts way different than Android or .NET weak references would do, so imo the most logical thing to do would be to ignore [weak self]

Oops my bad, I was confused in that last comment. While I do have circular references they aren’t the problem I’m solving with weak references. It’s simply a convenient way to implement particular patterns of caching and event handlers. e.g. See usage of WeakHashMap. Java explicitly supports the concept with these util classes and since it maps so neatly to swift weak I feel it would be nice to use them.