[swift-evolution] Proposal: Give weak references the ability to notify reference-holders when they transition to nil

Michael Henson mikehenson at gmail.com
Sun Dec 13 20:24:53 CST 2015


The use-case for this comes first from proposals to have a weak-reference
version of collection types. Implementing a notification signal of some
sort to weak reference-holders when the reference becomes nil would make
implementing those more straightforward.

It would also enable implementing cascading-weakness (or propagating
weakness):

class Thing {
  var text: String
}

class ThingProxy {
  weak var thing: Thing?
}

class ContrivedExample {
  weak var proxy: ThingProxy?
}

var example = ContrivedExample()

such that when example.proxy.thing becomes nil, and the ThingProxy instance
is no longer meaningful, example.proxy becomes nil as well.

SInce this is the germ of an idea, I'll avoid suggesting a syntax for the
mechanism so the discussion focuses on whether or not this is useful enough
as a feature to be implemented.

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151213/85ef7c16/attachment.html>


More information about the swift-evolution mailing list