Sunday, January 29, 2017

Swift Weak References and Type Erasure

Curt Clifton:

In one of my side projects, two interesting Swift problems—heterogeneous arrays and weak references—collided in an interesting way.

[…]

How can we clean up the old callers? We need some logic that tells us when a signal has been deallocated. But we don’t have a direct reference to any signals at all from the data model. We gave that up when we used type erasure. The only references to the signals are inside the callers.

That realization leads to the insight that unlocks this problem. We can capture a weak reference to the signal inside another closure that tells us whether or not a signal has been deallocated[…]

Comments RSS · Twitter

Leave a Comment