[swift-users] Memory management without ARC?

Joe Groff jgroff at apple.com
Sat Jan 30 15:49:13 CST 2016


> On Jan 30, 2016, at 10:56 AM, Matthias Zenger via swift-users <swift-users at swift.org> wrote:
> 
> Yes, that was my first attempt. The problem is that Swift 2 has no good support for weak references beyond weak properties. I'm using arrays throughout my code and those use strong references. Furthermore, my basic data structure is an enum with associated values. I haven't figured out a way to refer to the associated values weakly. This doesn't work:
> 
>   enum SchemeValue {
>     ...
>     case Vector(weak WrappedArray<SchemeValue>)
>   }

It's inconvenient, but you can use a wrapper struct to work around this limitation:

struct Weak<T: class> { weak var value: T? }

enum SchemeValue { case Vector(Weak<WrappedArray<SchemeValue>>) }

-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160130/258e74ea/attachment.html>


More information about the swift-users mailing list