Swift doesn't support stored properties in extensions. A way around that is to use objc_setAssociatedObject
as suggested here. What I'm trying to do is create a stored property that is a zeroing weak reference. Note that using OBJC_ASSOCIATION_ASSIGN
is not enough because it will not zero the reference when the object is deallocated.
I need something equivalent to
extension MyClass {
weak var myVar: NSObject?
}