Containers of weak references are valuable, but I suspect they will need to be completely distinct from Array and Set and Dictionary. The problem is that a weak reference can become nil at any time. This subverts the value semantics of Swift's current containers and defeats assumptions that typical container algorithms make. (For example, a typical sorting algorithm assumes that comparison results between two elements are consistent over time, but that isn't true if a weak reference disappears while a sort is in progress.)
Note that Foundation does not support weak references in NSDictionary or NSSet.
···
On Dec 10, 2015, at 2:55 PM, Riley Testut via swift-evolution <swift-evolution@swift.org> wrote:
I think native swift collections with support for weak references for their contents would be very useful, and in more places than just listed above. I don’t think Array could be easily extended to support it (what happens if a value is released? does everything shift down? do they keep their indices?), but Set and Dictionary (where the keys and/or values could be weak, akin to NSMapTable) would be good candidates IMO.
--
Greg Parker gparker@apple.com Runtime Wrangler